Skip to content

Commit

Permalink
Make mocha run all tests, fix broken tests (palantir#1677)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchen63 authored and adidahiya committed Nov 3, 2016
1 parent fb3b6ee commit d7e1cf8
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"lint:test": "tslint test/**/*.ts -e test/**/*.test.ts",
"test": "npm-run-all test:pre -p test:mocha test:rules",
"test:pre": "cd ./test/config && npm install",
"test:mocha": "mocha --reporter spec --colors build/test/**/*Tests.js build/test/assert.js",
"test:mocha": "mocha --reporter spec --colors \"build/test/**/*Tests.js\" build/test/assert.js",
"test:rules": "node ./build/test/ruleTestRunner.js",
"verify": "npm-run-all clean compile lint test docs"
},
Expand Down
2 changes: 1 addition & 1 deletion src/ruleLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function loadRules(ruleConfiguration: {[name: string]: any},
if (Rule == null) {
notFoundRules.push(ruleName);
} else {
if (isJs && Rule.metadata.typescriptOnly != null && Rule.metadata.typescriptOnly) {
if (isJs && Rule.metadata && Rule.metadata.typescriptOnly != null && Rule.metadata.typescriptOnly) {
notAllowedInJsRules.push(ruleName);
} else {
const all = "all"; // make the linter happy until we can turn it on and off
Expand Down
2 changes: 1 addition & 1 deletion src/tslintMulti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class MultiLinter {
}

if (sourceFile === undefined) {
throw new Error(`Invalid source file: ${fileName}. Ensure that the files supplied to lint have a .ts or .tsx extension.`);
throw new Error(`Invalid source file: ${fileName}. Ensure that the files supplied to lint have a .ts, .tsx, or .js extension.`);
}

// walk the code first to find all the intervals where rules are disabled
Expand Down
2 changes: 1 addition & 1 deletion test/config/tslint-almost-empty.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "rules": {} }
{ "jsRules": {}, "rules": {} }
3 changes: 3 additions & 0 deletions test/config/tslint-custom-rules-with-dir.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"rulesDirectory": "../files/custom-rules/",
"jsRules": {
"always-fail": true
},
"rules": {
"always-fail": true
}
Expand Down
4 changes: 4 additions & 0 deletions test/config/tslint-custom-rules-with-two-dirs.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"rulesDirectory": ["../files/custom-rules-2", "../files/custom-rules/"],
"jsRules": {
"always-fail": true,
"no-fail": true
},
"rules": {
"always-fail": true,
"no-fail": true
Expand Down
3 changes: 3 additions & 0 deletions test/config/tslint-custom-rules.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"jsRules": {
"always-fail": true
},
"rules": {
"always-fail": true
}
Expand Down
2 changes: 1 addition & 1 deletion test/config/tslint-with-bom.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "rules": { } }
{ "jsRules": { }, "rules": { } }
9 changes: 9 additions & 0 deletions test/config/tslint-with-comments.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{
// a nice comment
"jsRules": {
/*
"rule-one": true,
*/
"rule-two": true,
"rule-three": "//not a comment",
"rule-four": "/*also not a comment*/"
},
// a nice comment
"rules": {
/*
Expand Down
5 changes: 1 addition & 4 deletions test/configurationTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe("Configuration", () => {

it("extends with builtin", () => {
const config = loadConfigurationFromPath("./test/config/tslint-extends-builtin.json");
assert.isTrue(config.jsRules["no-var-keyword"]);
assert.isUndefined(config.jsRules["no-var-keyword"]);
assert.isFalse(config.jsRules["no-eval"]);
assert.isTrue(config.rules["no-var-keyword"]);
assert.isFalse(config.rules["no-eval"]);
Expand Down Expand Up @@ -144,9 +144,6 @@ describe("Configuration", () => {
it("extends with package installed relative to tslint", () => {
fs.writeFileSync(tmpfile, JSON.stringify({ extends: "tslint-test-config-non-relative" }));
let config = loadConfigurationFromPath(tmpfile);
assert.deepEqual(config.jsRules, {
"class-name": true,
});
assert.deepEqual(config.rules, {
"class-name": true,
});
Expand Down
5 changes: 3 additions & 2 deletions test/executable/executableTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ const EXECUTABLE_DIR = path.resolve(process.cwd(), "test", "executable");
const EXECUTABLE_PATH = path.resolve(EXECUTABLE_DIR, "npm-like-executable");
const TEMP_JSON_PATH = path.resolve(EXECUTABLE_DIR, "tslint.json");

describe("Executable", () => {

/* tslint:disable:only-arrow-functions */
describe("Executable", function() {
this.slow(3000); // the executable is JIT-ed each time it runs; avoid showing slowness warnings
describe("Files", () => {
it("exits with code 1 if no arguments passed", (done) => {
execCli([], (err, stdout, stderr) => {
Expand Down
3 changes: 3 additions & 0 deletions test/external/tslint-test-config-non-relative/tslint.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"jsRules": {
"class-name": true
},
"rules": {
"class-name": true
}
Expand Down
4 changes: 4 additions & 0 deletions test/external/tslint-test-config/tslint.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"extends": "tslint-test-custom-rules",
"jsRules": {
"rule-two": true,
"rule-four": true
},
"rules": {
"rule-two": true,
"rule-four": true
Expand Down
4 changes: 4 additions & 0 deletions test/external/tslint-test-custom-rules/tslint.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"rulesDirectory": ["./rules"],
"jsRules": {
"rule-one": true,
"rule-two": false
},
"rules": {
"rule-one": true,
"rule-two": false
Expand Down

0 comments on commit d7e1cf8

Please sign in to comment.