-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [email protected] update * update tests * update timeouts * update jest * remove duplicated test * separate integration tests * fixup integration test * try add teardown timeout * try increase teardown timeout * bisect on cli / integration tests * fixup bisect * reduce timeouts * bisect down to watcher, remove timeouts * increase jest watcher timeout * try node 14.17.2 * use check latest for nodejs * reinstate all tests * Revert "reinstate all tests" This reverts commit 1264641. * [email protected] * add teardown timeout * try defer unhandled rejections * note unhandled rejections * add completion delay * add logging * try non-sensical stackoverflow answer * note all unhandled rejections * easier debugging * fixup workflow * remove fake timers * process exit * next attempt * try all integration tests * reinstate full testing
- Loading branch information
1 parent
a529543
commit 2ba1c22
Showing
10 changed files
with
1,145 additions
and
888 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const fs = require("fs"); | ||
const { fork } = require("child_process"); | ||
const coverage = global.coverage; | ||
|
||
jest.setTimeout(20000); | ||
|
||
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); | ||
} | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
const os = require("os"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const coverage = global.coverage; | ||
|
||
// the twilio test can take a while (large codebase) | ||
jest.setTimeout(200000); | ||
|
||
let nccRun; | ||
if (coverage) { | ||
nccRun = require(__dirname + "/../src/cli.js"); | ||
} | ||
else { | ||
nccRun = require(__dirname + "/../dist/ncc/cli.js"); | ||
} | ||
|
||
const { Writable } = require('stream'); | ||
|
||
class StoreStream extends Writable { | ||
constructor (options) { | ||
super(options); | ||
this.data = []; | ||
} | ||
_write(chunk, encoding, callback) { | ||
this.data.push(chunk); | ||
callback(); | ||
} | ||
} | ||
|
||
for (const integrationTest of fs.readdirSync(__dirname + "/integration")) { | ||
// ignore e.g.: `.json` files | ||
if (!/\.(mjs|tsx?|js)$/.test(integrationTest)) continue; | ||
|
||
// disabled pending https://github.com/zeit/ncc/issues/141 | ||
if (integrationTest.endsWith('loopback.js')) continue; | ||
|
||
it(`should execute "ncc run ${integrationTest}"`, async () => { | ||
let expectedStdout; | ||
try { | ||
expectedStdout = fs.readFileSync(`${__dirname}/integration/${integrationTest}.stdout`).toString(); | ||
} | ||
catch (e) {} | ||
if (global.gc) global.gc(); | ||
const stdout = new StoreStream(); | ||
const stderr = new StoreStream(); | ||
try { | ||
await nccRun(["run", "--no-cache", "--no-asset-builds", `${__dirname}/integration/${integrationTest}`], stdout, stderr); | ||
} | ||
catch (e) { | ||
if (e.silent) { | ||
let lastErr = stderr.data[stderr.data.length - 1]; | ||
if (lastErr) | ||
throw new Error(lastErr); | ||
else | ||
throw new Error('Process exited with code ' + e.exitCode); | ||
} | ||
throw e; | ||
} | ||
if (expectedStdout) { | ||
let stdoutStr = ''; | ||
for (const chunk of stdout.data) | ||
stdoutStr += chunk.toString(); | ||
expect(stdoutStr.startsWith(expectedStdout)); | ||
} | ||
}); | ||
} | ||
|
||
it(`should execute "ncc build web-vitals" with target config`, async () => { | ||
if (global.gc) global.gc(); | ||
const stdout = new StoreStream(); | ||
const stderr = new StoreStream(); | ||
|
||
const tmpOut = path.join(os.tmpdir(), `ncc_${Math.random()}`) | ||
|
||
try { | ||
await nccRun(["build", "-o", tmpOut, "--target", "es5", require.resolve('web-vitals/dist/web-vitals.es5.min.js')], stdout, stderr); | ||
} | ||
catch (e) { | ||
if (e.silent) { | ||
let lastErr = stderr.data[stderr.data.length - 1]; | ||
if (lastErr) | ||
throw new Error(lastErr); | ||
else | ||
throw new Error('Process exited with code ' + e.exitCode); | ||
} | ||
throw e; | ||
} | ||
|
||
const outFile = path.join(tmpOut, 'index.js') | ||
const output = fs.readFileSync(outFile, 'utf8') | ||
|
||
// cleanup tmp output | ||
fs.unlinkSync(outFile) | ||
fs.rmdirSync(tmpOut) | ||
|
||
expect(output).toContain('function') | ||
// make sure es6 wrapper wasn't used | ||
expect(output).not.toContain('=>') | ||
|
||
await new Promise(resolve => setTimeout(resolve, 5000)); | ||
}); | ||
|
||
afterAll(() => { | ||
if (coverage) | ||
process.exit(0); | ||
}); | ||
|
||
// remove me when node.js makes this the default behavior | ||
process.on("unhandledRejection", e => { | ||
throw e; | ||
}); | ||
|
Oops, something went wrong.