From 12646417bb21100fcdffeeb2af1c898ce74d3f24 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Mon, 5 Jul 2021 12:27:36 -0700 Subject: [PATCH] reinstate all tests --- test/cli.test.js | 59 ++++++++++++++++++---------------------- test/integration.test.js | 1 - test/unit.test.js | 5 ---- test/watcher.test.js | 2 +- 4 files changed, 28 insertions(+), 39 deletions(-) diff --git a/test/cli.test.js b/test/cli.test.js index 379ed1be..adb4ae60 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -4,35 +4,30 @@ const coverage = global.coverage; jest.setTimeout(20000); -it('should have a test', function () { - expect('hello world'); -}); - -// for (const cliTest of eval(fs.readFileSync(__dirname + "/cli.js").toString())) { -// it(`should execute "ncc ${(cliTest.args || []).join(" ")}"`, async () => { -// const ps = fork(__dirname + (coverage ? "/../src/cli.js" : "/../dist/ncc/cli.js"), cliTest.args || [], { -// stdio: "pipe", -// env: { ...process.env, ...cliTest.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 }; -// let timedOut = false; -// if (cliTest.timeout) -// setTimeout(() => { -// timedOut = true; -// ps.kill(); -// }, cliTest.timeout); -// const code = await new Promise(resolve => ps.on("close", resolve)); -// if (typeof expected === "function") -// expect(expected(code, stdout, stderr, timedOut)).toBe(true); -// else { -// if ("code" in expected) -// expect(code).toBe(expected.code); -// if ("timeout" in expected) -// expect(timedOut).toBe(true); -// } -// }); -// } - +for (const cliTest of eval(fs.readFileSync(__dirname + "/cli.js").toString())) { + it(`should execute "ncc ${(cliTest.args || []).join(" ")}"`, async () => { + const ps = fork(__dirname + (coverage ? "/../src/cli.js" : "/../dist/ncc/cli.js"), cliTest.args || [], { + stdio: "pipe", + env: { ...process.env, ...cliTest.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 }; + let timedOut = false; + if (cliTest.timeout) + setTimeout(() => { + timedOut = true; + ps.kill(); + }, cliTest.timeout); + const code = await new Promise(resolve => ps.on("close", resolve)); + if (typeof expected === "function") + expect(expected(code, stdout, stderr, timedOut)).toBe(true); + else { + if ("code" in expected) + expect(code).toBe(expected.code); + if ("timeout" in expected) + expect(timedOut).toBe(true); + } + }); +} diff --git a/test/integration.test.js b/test/integration.test.js index a457ee07..6437f63f 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -38,7 +38,6 @@ for (const integrationTest of fs.readdirSync(__dirname + "/integration")) { // disabled pending https://github.com/zeit/ncc/issues/141 if (integrationTest.endsWith('loopback.js')) continue; - continue; it(`should execute "ncc run ${integrationTest}"`, async () => { let expectedStdout; try { diff --git a/test/unit.test.js b/test/unit.test.js index afd64413..11f4f40f 100644 --- a/test/unit.test.js +++ b/test/unit.test.js @@ -4,12 +4,7 @@ const ncc = coverage ? require("../src/index") : require("../"); jest.setTimeout(20000); -it('Should have a test', function () { - expect('hello world'); -}); - for (const unitTest of fs.readdirSync(`${__dirname}/unit`)) { - continue; it(`should generate correct output for ${unitTest}`, async () => { const testDir = `${__dirname}/unit/${unitTest}`; const expected = fs diff --git a/test/watcher.test.js b/test/watcher.test.js index 5d377bbd..e071c490 100644 --- a/test/watcher.test.js +++ b/test/watcher.test.js @@ -93,7 +93,7 @@ class CustomWatchFileSystem { } } -jest.setTimeout(60000); +jest.setTimeout(30000); it('Should support custom watch API', async () => { let buildCnt = 0;