Skip to content
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

chore: add windows to CI #896

Merged
merged 10 commits into from
Mar 31, 2022
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
node: [14, 16]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ module.exports = {
collectCoverageFrom: ["src/**/*.js"],
coverageReporters: ["html", "lcov"],
testEnvironment: "node",
testMatch: ["<rootDir>/test/?(*.)+(spec|test).js?(x)"]
testMatch: ["<rootDir>/test/**/*.test.js"]
};
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"build": "node scripts/build.js",
"build-test-binary": "cd test/binary && node-gyp rebuild && cp build/Release/hello.node ../integration/hello.node",
"codecov": "codecov",
"test": "node --expose-gc --max_old_space_size=4096 node_modules/.bin/jest",
"test-coverage": "node --expose-gc --max_old_space_size=4096 node_modules/.bin/jest --coverage --globals \"{\\\"coverage\\\":true}\" && codecov",
"test": "node --expose-gc --max_old_space_size=4096 node_modules/jest/bin/jest.js",
"test-coverage": "node --expose-gc --max_old_space_size=4096 node_modules/jest/bin/jest.js --coverage --globals \"{\\\"coverage\\\":true}\" && codecov",
"prepublishOnly": "node scripts/build.js --no-cache"
},
"devDependencies": {
Expand Down Expand Up @@ -60,7 +60,7 @@
"hot-shots": "^8.5.0",
"ioredis": "^4.2.0",
"isomorphic-unfetch": "^3.0.0",
"jest": "^27.4.5",
"jest": "^27.5.1",
"jimp": "^0.16.1",
"jugglingdb": "2.0.1",
"koa": "^2.6.2",
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ function ncc (
if (map && sourceMapRegister) {
const registerExt = esm ? '.cjs' : ext;
code = (esm ? `import './sourcemap-register${registerExt}';` : `require('./sourcemap-register${registerExt}');`) + code;
assets[`sourcemap-register${registerExt}`] = { source: fs.readFileSync(`${__dirname}/sourcemap-register.js.cache.js`), permissions: defaultPermissions };
assets[`sourcemap-register${registerExt}`] = { source: fs.readFileSync(join(__dirname, `sourcemap-register.js.cache.js`)), permissions: defaultPermissions };
}

if (esm && !filename.endsWith('.mjs')) {
Expand Down
14 changes: 8 additions & 6 deletions test/cli.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[
const { join } = require('path')

module.exports = [
{
args: ["run", "test/fixtures/ts-interop/interop.ts"],
expect: { code: 0 }
Expand All @@ -18,7 +20,7 @@
{
args: ["build", "test/integration/test.ts", "-o", "tmp"],
expect (code, stdout, stderr) {
return stdout.toString().indexOf('tmp/index.js') !== -1;
return stdout.toString().indexOf(join('tmp', 'index.js')) !== -1;
}
},
{
Expand Down Expand Up @@ -71,21 +73,21 @@
{
args: ["build", "-o", "tmp", "test/fixtures/test.cjs"],
expect (code, stdout, stderr) {
return stdout.toString().indexOf('tmp/index.cjs') !== -1;
return stdout.toString().indexOf(join('tmp', 'index.cjs')) !== -1;
}
},
{
args: ["build", "-o", "tmp", "test/fixtures/test.mjs"],
expect (code, stdout, stderr) {
return stdout.toString().indexOf('tmp/index.mjs') !== -1;
return stdout.toString().indexOf(join('tmp', 'index.mjs')) !== -1;
}
},
{
args: ["build", "-o", "tmp", "test/fixtures/test.mjs", "--stats-out", "tmp/stats.json"],
expect (code, stdout, stderr) {
const fs = require('fs');
try {
JSON.parse(fs.readFileSync('tmp/stats.json', 'utf8'));
JSON.parse(fs.readFileSync(join('tmp', 'stats.json'), 'utf8'));
} catch {
return false;
}
Expand All @@ -112,7 +114,7 @@
args: ["build", "-o", "tmp", "test/fixtures/module.cjs"],
expect (code, stdout) {
const fs = require('fs');
return code === 0 && fs.readFileSync('tmp/index.js', 'utf8').toString().indexOf('export {') === -1;
return code === 0 && fs.readFileSync(join('tmp', 'index.js'), 'utf8').toString().indexOf('export {') === -1;
}
}
]
9 changes: 5 additions & 4 deletions test/cli.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const fs = require("fs");
const { fork } = require("child_process");
const coverage = global.coverage;
const { join } = require("path");
const cliTests = require("./cli.js");
const file = global.coverage ? "/../src/cli.js" : "/../dist/ncc/cli.js";

jest.setTimeout(20000);

for (const cliTest of eval(fs.readFileSync(__dirname + "/cli.js").toString())) {
for (const cliTest of cliTests) {
it(`should execute "ncc ${(cliTest.args || []).join(" ")}"`, async () => {
const ps = fork(__dirname + (coverage ? "/../src/cli.js" : "/../dist/ncc/cli.js"), cliTest.args || [], {
const ps = fork(join(__dirname, file), cliTest.args || [], {
stdio: "pipe",
env: { ...process.env, ...cliTest.env },
});
Expand Down
10 changes: 10 additions & 0 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ const coverage = global.coverage;
// the twilio test can take a while (large codebase)
jest.setTimeout(200000);

const skipOnWindows = [
'binary-require.js',
'browserify-middleware.js',
'oracledb.js',
'tensorflow.js',
]

let nccRun;
if (coverage) {
nccRun = require(__dirname + "/../src/cli.js");
Expand Down Expand Up @@ -34,6 +41,9 @@ for (const integrationTest of fs.readdirSync(__dirname + "/integration")) {
// disabled pending https://github.com/zeit/ncc/issues/141
if (integrationTest.endsWith('loopback.js')) continue;

// ignore a few tests known to fail on windows
if (process.platform === 'win32' && skipOnWindows.includes(integrationTest)) continue;

it(`should execute "ncc run ${integrationTest}"`, async () => {
let expectedStdout;
try {
Expand Down
34 changes: 12 additions & 22 deletions test/unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,20 @@ const ncc = coverage ? require("../src/index") : require("../");

jest.setTimeout(20000);

function normalizeForWindows(str) {
return str.trim().replace(/\\r/g, '').replace(/\r/g, '').replace(/;+/g, ';');
}

for (const unitTest of fs.readdirSync(`${__dirname}/unit`)) {
it(`should generate correct output for ${unitTest}`, async () => {
if (process.platform === 'win32' && unitTest.includes('shebang')) {
continue;
}
it(`should generate correct output for ${unitTest}`, async () => {
const testDir = `${__dirname}/unit/${unitTest}`;
const expected = fs
.readFileSync(`${testDir}/output${coverage ? '-coverage' : ''}.js`)
.toString()
.trim()
// Windows support
.replace(/\r/g, "");
const expected = normalizeForWindows(fs.readFileSync(`${testDir}/output${coverage ? '-coverage' : ''}.js`, 'utf8'));
let expectedSourceMap;
try {
expectedSourceMap = fs
.readFileSync(`${testDir}/output${coverage ? '-coverage' : ''}.js.map`)
.toString()
.trim()
// Windows support
.replace(/\r/g, "");
expectedSourceMap = normalizeForWindows(fs.readFileSync(`${testDir}/output${coverage ? '-coverage' : ''}.js.map`, 'utf8'));
} catch (_) {}

let opts;
Expand Down Expand Up @@ -59,11 +56,7 @@ for (const unitTest of fs.readdirSync(`${__dirname}/unit`)) {
if (unitTest.includes('minify') && !unitTest.includes('minify-err')) {
expect(assets['index.js.map']).toBeDefined()
}
const actual = code
.trim()
// Windows support
.replace(/\r/g, "")
.replace(/;+/g, ";");
const actual = normalizeForWindows(code);
try {
expect(actual).toBe(expected);
} catch (e) {
Expand All @@ -73,10 +66,7 @@ for (const unitTest of fs.readdirSync(`${__dirname}/unit`)) {
}

if (map) {
const actualSourceMap = map
.trim()
// Windows support
.replace(/\r/g, "");
const actualSourceMap = normalizeForWindows(map);
try {
expect(actualSourceMap).toBe(expectedSourceMap);
} catch (e) {
Expand Down
Loading