From 8d40837002616401d9978bacd90a12dcc9a78c3e Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 28 May 2024 13:34:01 -0700 Subject: [PATCH] =?UTF-8?q?[Tests]=20strip=20node=E2=80=99s=20deprecation?= =?UTF-8?q?=20warnings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 5 +++-- test/async-await.js | 17 +++++++++-------- test/common.js | 7 +++++++ test/max_listeners.js | 6 +++++- test/no_only.js | 5 +++-- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index c577c99e..a4146999 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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": { diff --git a/test/async-await.js b/test/async-await.js index c69fde17..a035e42a 100644 --- a/test/async-await.js +++ b/test/async-await.js @@ -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; @@ -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(); }); }); @@ -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(); }); }); @@ -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(); }); }); @@ -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(); }); }); @@ -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(); }); }); @@ -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\');', ' ^', @@ -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) @@ -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(); diff --git a/test/common.js b/test/common.js index 92784335..45f735f7 100644 --- a/test/common.js +++ b/test/common.js @@ -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, ''); +}; diff --git a/test/max_listeners.js b/test/max_listeners.js index 34335d0c..7a6ecdb6 100644 --- a/test/max_listeners.js +++ b/test/max_listeners.js @@ -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); + } }); diff --git a/test/no_only.js b/test/no_only.js index 95ad07eb..f1d12092 100644 --- a/test/no_only.js +++ b/test/no_only.js @@ -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'); @@ -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', @@ -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 }); });