Skip to content

Commit

Permalink
test(cli): update cli tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Jul 27, 2022
1 parent 5c2d650 commit ee11256
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
19 changes: 0 additions & 19 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,6 @@ module.exports = [
return code === 1 && stderr.toString().indexOf('fail.ts:2:1') !== -1;
}
},
{
args: ["run", "test/fixtures/ts-error2/ts-error.ts"],
expect (code, stdout, stderr) {
return code === 1 && stderr.toString().indexOf('ts-error.ts(3,16)') !== -1 && stderr.toString().split('\n').length < 11;
}
},
{
args: ["run", "-t", "test/fixtures/with-type-errors/ts-error.ts"],
expect: { code: 0 }
},
{
args: ["build", "-o", "tmp", "test/fixtures/test.cjs"],
expect (code, stdout, stderr) {
Expand Down Expand Up @@ -101,15 +91,6 @@ module.exports = [
return stdout.length === 0;
}
},
{
args: ["build", "test/integration/test.ts"],
env: {
TYPESCRIPT_LOOKUP_PATH: '/tmp/nowhere'
},
expect (code, stdout) {
return code === 0 && stdout.indexOf('ncc built-in') !== -1;
},
},
{
args: ["build", "-o", "tmp", "test/fixtures/module.cjs"],
expect (code, stdout) {
Expand Down
17 changes: 9 additions & 8 deletions test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@ const file = global.coverage ? "/../src/cli.js" : "/../dist/ncc/cli.js";

jest.setTimeout(20000);

for (const cliTest of cliTests) {
it(`should execute "ncc ${(cliTest.args || []).join(" ")}"`, async () => {
const ps = fork(join(__dirname, file), cliTest.args || [], {
describe('cli', () => {
it.each(cliTests)('should execute ncc $args', async ({ args, env, expect: e, timeout }) => {

const ps = fork(join(__dirname, file), args || [], {
stdio: "pipe",
env: { ...process.env, ...cliTest.env },
env: { ...process.env, ...env },
});
let stderr = "", stdout = "";
ps.stderr.on("data", chunk => stderr += chunk.toString());
ps.stdout.on("data", chunk => stdout += chunk.toString());
const expected = cliTest.expect || { code: 0 };
const expected = e ?? { code: 0 };
let timedOut = false;
if (cliTest.timeout)
if (timeout)
setTimeout(() => {
timedOut = true;
ps.kill();
}, cliTest.timeout);
}, timeout);
const code = await new Promise(resolve => ps.on("close", resolve));
if (typeof expected === "function")
expect(expected(code, stdout, stderr, timedOut)).toBe(true);
Expand All @@ -31,4 +32,4 @@ for (const cliTest of cliTests) {
expect(timedOut).toBe(true);
}
});
}
});

0 comments on commit ee11256

Please sign in to comment.