Skip to content

Commit

Permalink
[Tests] strip node’s deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed May 28, 2024
1 parent 732268b commit 8d40837
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"aud": "^2.0.4",
"auto-changelog": "^2.4.0",
"concat-stream": "^1.6.2",
"cross-env": "^2.0.1",
"eclint": "^2.8.1",
"ecstatic": "^4.1.4",
"es-value-fixtures": "^1.4.2",
Expand Down Expand Up @@ -77,8 +78,8 @@
"pretest": "npm run lint",
"test": "npm-run-posix-or-windows tests-only",
"posttest": "aud --production",
"tests-only": "nyc tap 'test/*.js'",
"tests-only:windows": "nyc node_modules\\tap\\bin\\run.js test/*.js",
"tests-only": "cross-env NODE_OPTIONS='--no-warnings' nyc tap 'test/*.js'",
"tests-only:windows": "cross-env NODE_OPTIONS='--no-warnings' nyc node_modules\\tap\\bin\\run.js test/*.js",
"test:example": "find example -name '*.js' | grep -v fail | grep -v static | xargs tap"
},
"testling": {
Expand Down
17 changes: 9 additions & 8 deletions test/async-await.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var tap = require('tap');

var stripFullStack = require('./common').stripFullStack;
var stripDeprecations = require('./common').stripDeprecations;
var runProgram = require('./common').runProgram;

var nodeVersion = process.versions.node;
Expand Down Expand Up @@ -39,7 +40,7 @@ tap.test('async1', function (t) {
''
]);
t.same(r.exitCode, 0);
t.same(r.stderr.toString('utf8'), '');
t.same(stripDeprecations(r.stderr.toString('utf8')), '');
t.end();
});
});
Expand Down Expand Up @@ -75,7 +76,7 @@ tap.test('async2', function (t) {
''
]);
t.same(r.exitCode, 1);
t.same(r.stderr.toString('utf8'), '');
t.same(stripDeprecations(r.stderr.toString('utf8')), '');
t.end();
});
});
Expand All @@ -97,7 +98,7 @@ tap.test('async3', function (t) {
''
]);
t.same(r.exitCode, 0);
t.same(r.stderr.toString('utf8'), '');
t.same(stripDeprecations(r.stderr.toString('utf8')), '');
t.end();
});
});
Expand Down Expand Up @@ -126,7 +127,7 @@ tap.test('async4', function (t) {
''
]);
t.same(r.exitCode, 1);
t.same(r.stderr.toString('utf8'), '');
t.same(stripDeprecations(r.stderr.toString('utf8')), '');
t.end();
});
});
Expand Down Expand Up @@ -180,7 +181,7 @@ tap.test('async5', function (t) {
''
]);
t.same(r.exitCode, 1);
t.same(r.stderr.toString('utf8'), '');
t.same(stripDeprecations(r.stderr.toString('utf8')), '');
t.end();
});
});
Expand All @@ -204,7 +205,7 @@ tap.test('sync-error', function (t) {
});
stderr = lines.join('\n');

t.same(stripFullStack(stderr), [].concat(
t.same(stripFullStack(stripDeprecations(stderr)), [].concat(
'$TEST/async-await/sync-error.js:7',
' throw new Error(\'oopsie\');',
' ^',
Expand Down Expand Up @@ -256,7 +257,7 @@ tap.test('async-error', function (t) {
]);
t.same(r.exitCode, 1);

var stderr = r.stderr.toString('utf8');
var stderr = stripDeprecations(r.stderr.toString('utf8'));
var stderrLines = stderr.split('\n').filter(function (line) {
return !(/\(timers.js:/).test(line)
&& !(/\(internal\/timers.js:/).test(line)
Expand Down Expand Up @@ -300,7 +301,7 @@ tap.test('async-bug', function (t) {
]);
t.same(r.exitCode, 1);

var stderr = r.stderr.toString('utf8');
var stderr = stripDeprecations(r.stderr.toString('utf8'));

t.same(stderr, '');
t.end();
Expand Down
7 changes: 7 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,10 @@ module.exports.runProgram = function (folderName, fileName, cb) {
cb(result);
});
};

module.exports.stripDeprecations = function (msg) {
return String(msg)
.replace(/^\s*\(node:\d+\) ExperimentalWarning: The ESM module loader is experimental\.\s*$/g, '')
.replace(/\(node:\d+\) \[DEP0060\] DeprecationWarning: The `util\._extend` API is deprecated\. Please use Object\.assign\(\) instead\.(\n\(Use `node --trace-deprecation \.\.\.` to show where the warning was created\))?\s*/g, '')
.replace(/\(node:\d+\) \[DEP0060\] DeprecationWarning: The `punycode` API is deprecated\. Please use a userland alternative instead\.(\n\(Use `node --trace-deprecation \.\.\.` to show where the warning was created\))?\s*/g, '');
};
6 changes: 5 additions & 1 deletion test/max_listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
var spawn = require('child_process').spawn;
var path = require('path');

var stripDeprecations = require('./common').stripDeprecations;

var ps = spawn(process.execPath, [path.join(__dirname, 'max_listeners', 'source.js')]);

ps.stdout.pipe(process.stdout, { end: false });

ps.stderr.on('data', function (buf) {
console.log('not ok ' + buf);
if (stripDeprecations(buf)) {
console.log('not ok ' + buf);
}
});
5 changes: 3 additions & 2 deletions test/no_only.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var path = require('path');
var exec = require('child_process').exec;

var stripFullStack = require('./common').stripFullStack;
var stripDeprecations = require('./common').stripDeprecations;

var tapeBin = 'node ' + path.join(__dirname, '../bin/tape');

Expand Down Expand Up @@ -67,7 +68,7 @@ tap.test('Should run successfully if there is no only test', function (tt) {
exec(tapeBin + ' --no-only "**/test-a.js"', {
cwd: path.join(__dirname, 'no_only')
}, function (err, stdout, stderr) {
tt.match(stderr.toString('utf8'), /^\s*(\(node:\d+\) ExperimentalWarning: The ESM module loader is experimental\.)?\s*$/);
tt.equal(stripDeprecations(stderr.toString('utf8')), '');
tt.same(stripFullStack(stdout.toString('utf8')), [
'TAP version 13',
'# should pass',
Expand Down Expand Up @@ -104,7 +105,7 @@ tap.test('Should run successfully if there is an only test and no --no-only flag
'',
''
]);
tt.match(stderr.toString('utf8'), /^\s*(\(node:\d+\) ExperimentalWarning: The ESM module loader is experimental\.)?\s*$/);
tt.equal(stripDeprecations(stderr.toString('utf8')), '');
tt.equal(err, null); // code 0
});
});

0 comments on commit 8d40837

Please sign in to comment.