Skip to content

Commit

Permalink
test: simplify common/index.js
Browse files Browse the repository at this point in the history
Move single or trivial and limited use things out of
common/index.js for the purpose of simplifying and reducing
common/index.js

PR-URL: nodejs#56712
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
  • Loading branch information
jasnell authored and nodejs-github-bot committed Jan 25, 2025
1 parent 4a5d2c7 commit 0713ee3
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 28 deletions.
6 changes: 0 additions & 6 deletions test/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,6 @@ Platform check for IBMi.

Platform check for Linux.

### `isLinuxPPCBE`

* [\<boolean>][<boolean>]

Platform check for Linux on PowerPC.

### `isMacOS`

* [\<boolean>][<boolean>]
Expand Down
12 changes: 0 additions & 12 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1034,11 +1034,6 @@ const common = {
return require('os').type() === 'OS400';
},

get isLinuxPPCBE() {
return (process.platform === 'linux') && (process.arch === 'ppc64') &&
(require('os').endianness() === 'BE');
},

get localhostIPv4() {
if (localhostIPv4 !== null) return localhostIPv4;

Expand Down Expand Up @@ -1067,13 +1062,6 @@ const common = {
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';
},

get isInsideDirWithUnusualChars() {
return __dirname.includes('%') ||
(!isWindows && __dirname.includes('\\')) ||
Expand Down
4 changes: 0 additions & 4 deletions test/common/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const {
allowGlobals,
buildType,
canCreateSymLink,
checkoutEOL,
childShouldThrowAndAbort,
createZeroFilledFile,
enoughTestMem,
Expand All @@ -27,7 +26,6 @@ const {
isIBMi,
isInsideDirWithUnusualChars,
isLinux,
isLinuxPPCBE,
isMainThread,
isOpenBSD,
isMacOS,
Expand Down Expand Up @@ -59,7 +57,6 @@ export {
allowGlobals,
buildType,
canCreateSymLink,
checkoutEOL,
childShouldThrowAndAbort,
createRequire,
createZeroFilledFile,
Expand All @@ -81,7 +78,6 @@ export {
isIBMi,
isInsideDirWithUnusualChars,
isLinux,
isLinuxPPCBE,
isMainThread,
isOpenBSD,
isMacOS,
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-source-map-enable.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ function nextdir() {

// Persists line lengths for in-memory representation of source file.
{
const checkoutEOL = fs.readFileSync(__filename).includes('\r\n') ? '\r\n' : '\n';
const coverageDirectory = nextdir();
spawnSync(process.execPath, [
require.resolve('../fixtures/source-map/istanbul-throw.js'),
Expand All @@ -250,7 +251,7 @@ function nextdir() {
'istanbul-throw.js',
coverageDirectory
);
if (common.checkoutEOL === '\r\n') {
if (checkoutEOL === '\r\n') {
assert.deepStrictEqual(sourceMap.lineLengths, [1086, 31, 185, 649, 0]);
} else {
assert.deepStrictEqual(sourceMap.lineLengths, [1085, 30, 184, 648, 0]);
Expand Down
11 changes: 9 additions & 2 deletions test/tick-processor/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ const {
isWindows,
isSunOS,
isAIX,
isLinuxPPCBE,
isFreeBSD,
} = require('../common');

const { endianness } = require('os');

function isLinuxPPCBE() {
return (process.platform === 'linux') &&
(process.arch === 'ppc64') &&
(endianness() === 'BE');
}

module.exports = {
isCPPSymbolsNotMapped: isWindows ||
isSunOS ||
isAIX ||
isLinuxPPCBE ||
isLinuxPPCBE() ||
isFreeBSD,
};
11 changes: 8 additions & 3 deletions test/wasi/test-wasi-io.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
'use strict';
const common = require('../common');
const { checkoutEOL } = common;
require('../common');
const { readFileSync } = require('fs');
const { testWasiPreview1 } = require('../common/wasi');

const checkoutEOL = readFileSync(__filename).includes('\r\n') ? '\r\n' : '\n';

// TODO(@jasnell): It's not entirely clear what this test is asserting.
// More comments would be helpful.

testWasiPreview1(['freopen'], {}, { stdout: `hello from input2.txt${checkoutEOL}` });
testWasiPreview1(['read_file'], {}, { stdout: `hello from input.txt${checkoutEOL}` });
testWasiPreview1(['read_file_twice'], {}, {
stdout: `hello from input.txt${checkoutEOL}hello from input.txt${checkoutEOL}`,
});
// Tests that are currently unsupported on Windows.
if (!common.isWindows) {
if (process.platform !== 'win32') {
testWasiPreview1(['stdin'], { input: 'hello world' }, { stdout: 'hello world' });
}

0 comments on commit 0713ee3

Please sign in to comment.