Skip to content

Commit

Permalink
test: make tests pass on Windows with Unix EOL
Browse files Browse the repository at this point in the history
It is possible on Windows to configure Git to checkout line-endings
"as-is", which for Node.js means Unix-style.
This change makes the tests that rely on line endings pass in that case.

PR-URL: #40002
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
targos authored and BethGriggs committed Sep 21, 2021
1 parent 73aa4e3 commit 67bbfeb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
8 changes: 7 additions & 1 deletion test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -878,8 +878,14 @@ const common = {
throw new Error('common.PORT cannot be used in a parallelized test');
}
return +process.env.NODE_COMMON_PORT || 12346;
}
},

/**
* Returns the EOL character used by this Git checkout.
*/
get checkoutEOL() {
return fs.readFileSync(__filename).includes('\r\n') ? '\r\n' : '\n';
},
};

const validProperties = new Set(Object.keys(common));
Expand Down
4 changes: 2 additions & 2 deletions test/es-module/test-esm-invalid-pjson.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { mustCall, isWindows } = require('../common');
const { mustCall, checkoutEOL } = require('../common');
const fixtures = require('../common/fixtures');
const { spawn } = require('child_process');
const { strictEqual, ok } = require('assert');
Expand All @@ -21,7 +21,7 @@ child.on('close', mustCall((code, signal) => {
stderr.includes(
`[ERR_INVALID_PACKAGE_CONFIG]: Invalid package config ${invalidJson} ` +
`while importing "invalid-pjson" from ${entry}. ` +
`Unexpected token } in JSON at position ${isWindows ? 16 : 14}`
`Unexpected token } in JSON at position ${12 + checkoutEOL.length * 2}`
),
stderr);
}));
2 changes: 1 addition & 1 deletion test/parallel/test-source-map-enable.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ function nextdir() {
'istanbul-throw.js',
coverageDirectory
);
if (common.isWindows) {
if (common.checkoutEOL === '\r\n') {
assert.deepStrictEqual(sourceMap.lineLengths, [1086, 31, 185, 649, 0]);
} else {
assert.deepStrictEqual(sourceMap.lineLengths, [1085, 30, 184, 648, 0]);
Expand Down
8 changes: 4 additions & 4 deletions test/wasi/test-wasi.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if (process.argv[2] === 'wasi-child') {
} else {
const assert = require('assert');
const cp = require('child_process');
const { EOL } = require('os');
const { checkoutEOL } = common;

function runWASI(options) {
console.log('executing', options.test);
Expand Down Expand Up @@ -69,7 +69,7 @@ if (process.argv[2] === 'wasi-child') {
}
runWASI({ test: 'exitcode', exitCode: 120 });
runWASI({ test: 'fd_prestat_get_refresh' });
runWASI({ test: 'freopen', stdout: `hello from input2.txt${EOL}` });
runWASI({ test: 'freopen', stdout: `hello from input2.txt${checkoutEOL}` });
runWASI({ test: 'ftruncate' });
runWASI({ test: 'getentropy' });

Expand All @@ -87,10 +87,10 @@ if (process.argv[2] === 'wasi-child') {
runWASI({ test: 'readdir' });
}

runWASI({ test: 'read_file', stdout: `hello from input.txt${EOL}` });
runWASI({ test: 'read_file', stdout: `hello from input.txt${checkoutEOL}` });
runWASI({
test: 'read_file_twice',
stdout: `hello from input.txt${EOL}hello from input.txt${EOL}`
stdout: `hello from input.txt${checkoutEOL}hello from input.txt${checkoutEOL}`
});
runWASI({ test: 'stat' });
runWASI({ test: 'write_file' });
Expand Down

0 comments on commit 67bbfeb

Please sign in to comment.