Skip to content

Added tests for stderr from missing tslint.json files #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ coverage/
node_modules/
src/**/*.js
test/*.js
~test/jest.config.js
test/tests/**/.eslintrc*
8 changes: 6 additions & 2 deletions docs/Testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ npm run test:end-to-end
End-to-end tests that execute the `bin/tslint-to-eslint` command and validate outputs are generated from the directories in `test/tests/`.
Each directory there contains:

- `test.ts`: Test file that runs `createTests(__dirname);` to set up tests in that directory
- `.eslintrc.json`: `.gitignore`d output from the most recent test run
- `expected.json`: Expected output ESLint configuration
- `stderr.txt`: Any output written to the process `stderr`
- `stdout.txt`: Any output written to the process `stdout`
- `stderr.txt`: Expected output written to the process `stderr`
- `stdout.txt`: Expected output written to the process `stdout`
- `tslint.json`: Original TSLint configuration file to convert

Within each directory, a test suite will execute `bin/tslint-to-eslint` and validate the outputs match what's on disk.

Use `npm run test:end-to-end:accept` to overwrite the expected contents of files with what is actually written.
These behave similarly to updating snapshots in snapshot testing.
8 changes: 2 additions & 6 deletions test/createTestArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ const readdir = promisify(fs.readdir);

export const createTestArgs = async (cwd: string) => {
const items = new Set(await readdir(cwd));
const flags = [
"--config",
path.join(cwd, ".eslintrc.json"),
"--tslint",
path.join(cwd, "tslint.json"),
];
const flags = ["--config", path.join(cwd, ".eslintrc.json")];

if (items.has("tslint.json")) {
flags.push("--tslint", path.join(cwd, "tslint.json"));
}

return flags.map(flag => `"${flag}"`).join(" ");
Expand Down
17 changes: 10 additions & 7 deletions test/createTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,24 @@ import { assertFileContents } from "./expectFileContains";
const exec = promisify(cp.exec);
const readFile = promisify(fs.readFile);

export const createTests = (testName: string, accept: boolean) => {
const cwd = path.join(__dirname, "tests", testName);
export const createTests = (cwd: string) => {
const testName = path.basename(cwd);
const accept = "acceptTestChanges" in globalThis;
const cwdPath = (fileName: string) => path.join(cwd, fileName);
const readTestFile = async (fileName: string) => (await readFile(cwdPath(fileName))).toString();

return () => {
describe(testName, () => {
let result: PromiseValue<ReturnType<typeof exec>>;
beforeAll(async () => {
// Arrange
const args = await createTestArgs(cwd);

// Act
result = await exec(`ts-node bin/tslint-to-eslint-config ${args}`);
try {
result = await exec(`ts-node bin/tslint-to-eslint-config ${args}`);
} catch (error) {
result = error;
}
});

test("configuration output", async () => {
Expand All @@ -33,14 +38,12 @@ export const createTests = (testName: string, accept: boolean) => {
);
});

// test("info log output", () => {});

test("stderr", async () => {
await assertFileContents(cwdPath("stderr.txt"), result.stderr, accept);
});

test("stdout", async () => {
await assertFileContents(cwdPath("stdout.txt"), result.stdout, accept);
});
};
});
};
2 changes: 1 addition & 1 deletion test/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
testRegex: "test/runEndToEndTests.ts",
testRegex: "test(.*)\\test\\.ts$",
testEnvironment: "node",
};
12 changes: 0 additions & 12 deletions test/runEndToEndTests.ts

This file was deleted.

50 changes: 50 additions & 0 deletions test/tests/missing tslint.json/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"env": {
"es6": true,
"node": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint",
"@typescript-eslint/tslint"
],
"rules": {
"@typescript-eslint/array-type": "error",
"@typescript-eslint/interface-name-prefix": "error",
"@typescript-eslint/member-ordering": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-param-reassign": "off",
"@typescript-eslint/no-parameter-properties": "off",
"@typescript-eslint/no-use-before-declare": "off",
"@typescript-eslint/promise-function-async": "off",
"@typescript-eslint/unbound-method": "off",
"arrow-body-style": "off",
"default-case": "off",
"linebreak-style": "off",
"no-bitwise": "off",
"no-empty": "off",
"no-empty-functions": "off",
"no-magic-numbers": "off",
"prefer-template": "off",
"@typescript-eslint/tslint/config": [
"error",
{
"rules": {
"no-implicit-dependencies": [
true,
"dev"
],
"strict-boolean-expressions": [
true,
"allow-boolean-or-undefined",
"allow-number"
]
}
}
]
}
}
5 changes: 5 additions & 0 deletions test/tests/missing tslint.json/stderr.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
❌ Could not start tslint-to-eslint: ❌
Command failed: tslint --print-config "./tslint.json"
Could not find configuration path. Try passing a --config to your tslint.json.


Empty file.
3 changes: 3 additions & 0 deletions test/tests/missing tslint.json/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { createTests } from "../../createTests";

createTests(__dirname);
2 changes: 1 addition & 1 deletion test/tests/standalone tslint.json/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@
}
]
}
}
}
2 changes: 1 addition & 1 deletion test/tests/standalone tslint.json/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@
}
]
}
}
}
7 changes: 4 additions & 3 deletions test/tests/standalone tslint.json/stdout.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
✨ 17 rules replaced with their ESLint equivalents. ✨
️👀 2 rules do not yet have ESLint equivalents; defaulting to eslint-plugin-tslint. 👀
✅ All is well! ✅
✨ 17 rules replaced with their ESLint equivalents. ✨
️👀 2 rules do not yet have ESLint equivalents; defaulting to eslint-plugin-tslint. 👀
✅ All is well! ✅

3 changes: 3 additions & 0 deletions test/tests/standalone tslint.json/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { createTests } from "../../createTests";

createTests(__dirname);
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
"strictNullChecks": true,
"strictPropertyInitialization": true,
"target": "esnext"
}
},
"exclude": ["test/tests/**/*"]
}