Skip to content

Commit 25a2169

Browse files
committed
fix: remove custom test reporter
1 parent 472c33b commit 25a2169

File tree

12 files changed

+112
-186
lines changed

12 files changed

+112
-186
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Contributor guide: https://github.com/nodejs/node/blob/main/CONTRIBUTING.md
77
##### Checklist
88
<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->
99

10-
- [ ] `npm install && npm test` passes
10+
- [ ] `npm install && npm run lint && npm test` passes
1111
- [ ] tests are included <!-- Bug fixes and new features should include tests -->
1212
- [ ] documentation is changed or added
1313
- [ ] commit message follows [commit guidelines](https://github.com/googleapis/release-please#how-should-i-write-my-commits)

.github/workflows/tests.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,24 @@ jobs:
1818
- uses: actions/checkout@v4
1919
- run: pip install --user ruff
2020
- run: ruff --output-format=github --select="E,F,PLC,PLE,UP,W,YTT" --ignore="E721,PLC1901,S101,UP031" --target-version=py38 .
21+
Lint_JS:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout Repository
25+
uses: actions/checkout@v4
26+
- name: Use Node.js 20.x
27+
uses: actions/setup-node@v3
28+
with:
29+
node-version: 20.x
30+
- name: Install Dependencies
31+
run: npm install --no-progress
32+
- name: Lint
33+
run: npm run lint
2134
Engines:
2235
runs-on: ubuntu-latest
2336
steps:
2437
- name: Checkout Repository
25-
uses: actions/checkout@v3
38+
uses: actions/checkout@v4
2639
- name: Use Node.js 20.x
2740
uses: actions/setup-node@v3
2841
with:
@@ -77,7 +90,11 @@ jobs:
7790
if: runner.os != 'Windows'
7891
shell: bash
7992
run: npm test --python="${pythonLocation}/python"
93+
env:
94+
FAST_TEST: ${{ (matrix.node == '20.x' && matrix.python == '3.12') && '0' || '1' }}
8095
- name: Run tests (Windows)
8196
if: runner.os == 'Windows'
8297
shell: pwsh
8398
run: npm run test --python="${env:pythonLocation}\\python.exe"
99+
env:
100+
FAST_TEST: ${{ (matrix.node == '20.x' && matrix.python == '3.12') && '0' || '1' }}

bin/node-gyp.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ if (prog.devDir) {
3232

3333
if (prog.todo.length === 0) {
3434
if (~process.argv.indexOf('-v') || ~process.argv.indexOf('--version')) {
35-
console.log('v%s', prog.version)
35+
log.stdout('v%s', prog.version)
3636
} else {
37-
console.log('%s', prog.usage())
37+
log.stdout('%s', prog.usage())
3838
}
3939
process.exit(0)
4040
}
@@ -82,12 +82,12 @@ async function run () {
8282

8383
if (command.name === 'list') {
8484
if (args.length) {
85-
args.forEach((version) => console.log(version))
85+
args.forEach((version) => log.stdout(version))
8686
} else {
87-
console.log('No node development files installed. Use `node-gyp install` to install a version.')
87+
log.stdout('No node development files installed. Use `node-gyp install` to install a version.')
8888
}
8989
} else if (args.length >= 1) {
90-
console.log(...args.slice(1))
90+
log.stdout(...args.slice(1))
9191
}
9292

9393
// now run the next command in the queue

lib/install.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const processRelease = require('./process-release')
1414
const win = process.platform === 'win32'
1515

1616
async function install (gyp, argv) {
17-
console.log()
17+
log.stdout()
1818
const release = processRelease(argv, gyp, process.version, process.release)
1919
// Detecting target_arch based on logic from create-cnfig-gyp.js. Used on Windows only.
2020
const arch = win ? (gyp.opts.target_arch || gyp.opts.arch || process.arch || 'ia32') : ''

lib/log.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ class Logger {
7373
style: { fg: 'red', bg: 'black' }
7474
}]
7575

76-
constructor () {
76+
constructor (stream) {
7777
process.on('log', (...args) => this.#onLog(...args))
7878
this.#levels = new Map(this.#levels.map((level, index) => [level.id, { ...level, index }]))
7979
this.level = 'info'
80-
this.stream = process.stderr
80+
this.stream = stream
8181
procLog.pause()
8282
}
8383

@@ -158,8 +158,12 @@ class Logger {
158158
}
159159
}
160160

161+
// used to suppress logs in tests
162+
const NULL_LOGGER = !!process.env.NODE_GYP_NULL_LOGGER
163+
161164
module.exports = {
162-
logger: new Logger(),
165+
logger: new Logger(NULL_LOGGER ? null : process.stderr),
166+
stdout: NULL_LOGGER ? () => {} : (...args) => console.log(...args),
163167
withPrefix,
164168
...procLog
165169
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@
4545
},
4646
"scripts": {
4747
"lint": "standard \"*/*.js\" \"test/**/*.js\" \".github/**/*.js\"",
48-
"test": "npm run lint && mocha --timeout 15000 --reporter=test/reporter.js test/test-download.js test/test-*"
48+
"test": "NODE_GYP_NULL_LOGGER=true mocha --timeout 15000 test/test-download.js test/test-*"
4949
}
5050
}

test/common.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const envPaths = require('env-paths')
2+
const semver = require('semver')
23

34
module.exports.devDir = () => envPaths('node-gyp', { suffix: '' }).cache
45

@@ -15,3 +16,7 @@ module.exports.poison = (object, property) => {
1516
}
1617
Object.defineProperty(object, property, descriptor)
1718
}
19+
20+
module.exports.skip = process.env.FAST_TEST === '1' ||
21+
process.release.name !== 'node' ||
22+
semver.prerelease(process.version) !== null

test/reporter.js

Lines changed: 0 additions & 75 deletions
This file was deleted.

test/test-addon.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const { describe, it } = require('mocha')
44
const assert = require('assert')
55
const path = require('path')
66
const fs = require('graceful-fs')
7-
const { execFileSync, execFile } = require('child_process')
7+
const cp = require('child_process')
88
const os = require('os')
99
const addonPath = path.resolve(__dirname, 'node_modules', 'hello_world')
1010
const nodeGyp = path.resolve(__dirname, '..', 'bin', 'node-gyp.js')
@@ -14,18 +14,18 @@ function runHello (hostProcess) {
1414
hostProcess = process.execPath
1515
}
1616
const testCode = "console.log(require('hello_world').hello())"
17-
return execFileSync(hostProcess, ['-e', testCode], { cwd: __dirname }).toString()
17+
return cp.execFileSync(hostProcess, ['-e', testCode], { cwd: __dirname }).toString()
1818
}
1919

2020
function getEncoding () {
2121
const code = 'import locale;print(locale.getdefaultlocale()[1])'
22-
return execFileSync('python', ['-c', code]).toString().trim()
22+
return cp.execFileSync('python', ['-c', code]).toString().trim()
2323
}
2424

2525
function checkCharmapValid () {
2626
let data
2727
try {
28-
data = execFileSync('python', ['fixtures/test-charmap.py'],
28+
data = cp.execFileSync('python', ['fixtures/test-charmap.py'],
2929
{ cwd: __dirname })
3030
} catch (err) {
3131
return false
@@ -34,13 +34,25 @@ function checkCharmapValid () {
3434
return lines.pop() === 'True'
3535
}
3636

37+
const omit = (obj, ...keys) => {
38+
const res = {}
39+
for (const key of Object.keys(obj)) {
40+
if (!keys.includes(key)) {
41+
res[key] = obj[key]
42+
}
43+
}
44+
return res
45+
}
46+
3747
describe('addon', function () {
3848
this.timeout(300000)
3949

50+
const execFile = (cmd, fn) => cp.execFile(process.execPath, cmd, { env: omit(process.env, 'NODE_GYP_NULL_LOGGER') }, fn)
51+
4052
it('build simple addon', function (done) {
4153
// Set the loglevel otherwise the output disappears when run via 'npm test'
4254
const cmd = [nodeGyp, 'rebuild', '-C', addonPath, '--loglevel=verbose']
43-
const proc = execFile(process.execPath, cmd, function (err, stdout, stderr) {
55+
const proc = execFile(cmd, function (err, stdout, stderr) {
4456
const logLines = stderr.toString().trim().split(/\r?\n/)
4557
const lastLine = logLines[logLines.length - 1]
4658
assert.strictEqual(err, null)
@@ -105,7 +117,7 @@ describe('addon', function () {
105117
'--loglevel=verbose',
106118
'-nodedir=' + testNodeDir
107119
]
108-
const proc = execFile(process.execPath, cmd, function (err, stdout, stderr) {
120+
const proc = execFile(cmd, function (err, stdout, stderr) {
109121
try {
110122
fs.unlink(testNodeDir)
111123
} catch (err) {
@@ -124,18 +136,13 @@ describe('addon', function () {
124136
})
125137

126138
it('addon works with renamed host executable', function (done) {
127-
// No `fs.copyFileSync` before node8.
128-
if (process.version.substr(1).split('.')[0] < 8) {
129-
return this.skip('skipping test for old node version')
130-
}
131-
132139
this.timeout(300000)
133140

134141
const notNodePath = path.join(os.tmpdir(), 'notnode' + path.extname(process.execPath))
135142
fs.copyFileSync(process.execPath, notNodePath)
136143

137144
const cmd = [nodeGyp, 'rebuild', '-C', addonPath, '--loglevel=verbose']
138-
const proc = execFile(process.execPath, cmd, function (err, stdout, stderr) {
145+
const proc = execFile(cmd, function (err, stdout, stderr) {
139146
const logLines = stderr.toString().trim().split(/\r?\n/)
140147
const lastLine = logLines[logLines.length - 1]
141148
assert.strictEqual(err, null)

test/test-configure-python.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const assert = require('assert')
55
const path = require('path')
66
const devDir = require('./common').devDir()
77
const gyp = require('../lib/node-gyp')
8-
const log = require('../lib/log')
98
const requireInject = require('require-inject')
9+
1010
const configure = requireInject('../lib/configure', {
1111
'graceful-fs': {
1212
openSync: () => 0,
@@ -19,8 +19,6 @@ const configure = requireInject('../lib/configure', {
1919
}
2020
})
2121

22-
log.logger.stream = null
23-
2422
const EXPECTED_PYPATH = path.join(__dirname, '..', 'gyp', 'pylib')
2523
const SEPARATOR = process.platform === 'win32' ? ';' : ':'
2624
const SPAWN_RESULT = cb => ({ on: function () { cb() } })

0 commit comments

Comments
 (0)