Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All: Update node-watch dependency and test fixtures for Node 12+ #1448

Merged
merged 2 commits into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
os: linux
language: node_js
node_js:
- "14"
- "12"
- "10"
- "8"
- "6"
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"commander": "2.12.2",
"js-reporters": "1.2.1",
"resolve": "1.9.0",
"node-watch": "0.6.1",
"node-watch": "0.6.4",
"minimatch": "3.0.4"
},
"devDependencies": {
Expand Down
15 changes: 7 additions & 8 deletions test/cli/fixtures/expected/tap-outputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ not ok 2 global failure
# fail 2
`,

// in node 8, the stack trace includes 'at <anonymous>. But not in node 6 or 10.
// Ignore the last frame about Node processing ticks (differs between Node 10 ad 12+)
"qunit no-tests":
`TAP version 13
not ok 1 global failure
Expand All @@ -157,7 +157,7 @@ not ok 1 global failure
at advanceTestQueue (.*)
at Object.advance (.*)
at unblockAndAdvanceQueue (.*)(\n at <anonymous>)?
at process._tickCallback (.*)
at .*
...
1..1
# pass 0
Expand All @@ -174,9 +174,8 @@ not ok 1 timeout > first
severity: failed
actual: null
expected: undefined
stack: at ontimeout (.*)
at tryOnTimeout (.*)
(.*)\\s*(.*)?
stack: at .* (.*timers.js.*)
at .*(\n at .*)?(\n at .*)?
...
ok 2 timeout > second
1..2
Expand All @@ -186,7 +185,7 @@ ok 2 timeout > second
# fail 1
`,

// in node 8, the stack trace includes 'at <anonymous>. But not in node 6 or 10.
// Ignore the last frame about Node processing ticks (differs between Node 10 ad 12+)
"qunit qunit --filter 'no matches' test":
`TAP version 13
not ok 1 global failure
Expand All @@ -200,7 +199,7 @@ not ok 1 global failure
at advanceTestQueue (.*)
at Object.advance (.*)
at unblockAndAdvanceQueue (.*)(\n at <anonymous>)?
at process._tickCallback (.*)
at .*
...
1..1
# pass 0
Expand All @@ -220,7 +219,7 @@ ok 1 Single > has a test
# todo 0
# fail 0`,

"node --expose-gc --allow-natives-syntax ../../../bin/qunit.js memory-leak/*.js":
"node --expose-gc ../../../bin/qunit.js memory-leak/*.js":
`TAP version 13
ok 1 some nested module > can call method on foo
ok 2 later thing > has released all foos
Expand Down
5 changes: 5 additions & 0 deletions test/cli/fixtures/memory-leak/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"parserOptions": {
"ecmaVersion": 2017
}
}
72 changes: 43 additions & 29 deletions test/cli/fixtures/memory-leak/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* globals gc */

const v8 = require( "v8" );

const foos = new WeakSet();
class Foo {
constructor() {
Expand All @@ -13,48 +15,60 @@ class Foo {
destroy() { }
}

function streamToString( stream ) {
const chunks = [];
return new Promise( ( resolve, reject ) => {
stream.on( "data", chunk => chunks.push( chunk ) );
stream.on( "error", reject );
stream.on( "end", () => resolve( Buffer.concat( chunks ).toString( "utf8" ) ) );
} );
}

QUnit.module( "some nested module", function( hooks ) {
let foo;
let foo1;

hooks.beforeEach( function() {
foo = new Foo();
foo1 = new Foo();
} );

hooks.afterEach( function() {
foo.destroy();
foo1.destroy();
} );

QUnit.test( "can call method on foo", function( assert ) {
assert.equal( foo.sayHello(), "Hi!" );
assert.equal( foo1.sayHello(), "Hi!" );
} );

} );

QUnit.module( "later thing", function() {
QUnit.test( "has released all foos", function( assert ) {

// Without async here, the test runner is recursive, and therefore the `foo`
// instance is still retained.
return Promise.resolve()
.then( () => {

// Requires `--expose-gc` flag to function properly.
gc();

// Using `new Function` here to avoid a syntax error.
const retainedFoos = new Function(
"foos",
"return %GetWeakSetValues(foos, 0)"
)( foos );

assert.equal( retainedFoos.length, 0 );
} )
.catch( error => {
if ( error instanceof SyntaxError ) {
console.log( "Must launch Node 9 with `--expose-gc --allow-natives-syntax`" );
} else {
throw error;
}
} );
QUnit.test( "has released all foos", async function( assert ) {

// Create another one to ensure our heap match logic is working.
let foo2 = new Foo();

// The snapshot is expected to contain something like this:
// > "part of key (Foo @…) -> value (…) pair in WeakMap (…)"
// It is important that the regex uses \d and that the above
// comment doesn't include a number after "@", as otherwise
// it will match the memory relating to this function's code.
const reHeap = /^[^\n]+Foo @\d[^\n]+/gm;

let snapshot = await streamToString( v8.getHeapSnapshot() );
let matches = snapshot.match( reHeap );
assert.ok( matches && matches.length, "found local Foo in heap" );

snapshot = matches = null;
foo2.destroy();

// Comment out the below to test the failure mode
foo2 = null;

// Requires `--expose-gc` flag to function properly.
gc();

snapshot = await streamToString( v8.getHeapSnapshot() );
matches = snapshot.match( reHeap );
assert.strictEqual( null, matches, "the after heap" );
} );
} );
6 changes: 4 additions & 2 deletions test/cli/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ QUnit.module( "CLI Main", function() {
}
} ) );

if ( semver.gte( process.versions.node, "9.0.0" ) ) {
// https://nodejs.org/docs/v14.0.0/api/v8.html#v8_v8_getheapsnapshot
// Created in Node 11.x, but starts working the way we need from Node 14.
if ( semver.gte( process.versions.node, "14.0.0" ) ) {
QUnit.test( "callbacks and hooks from modules are properly released for garbage collection", co.wrap( function* ( assert ) {
const command = "node --expose-gc --allow-natives-syntax ../../../bin/qunit.js memory-leak/*.js";
const command = "node --expose-gc ../../../bin/qunit.js memory-leak/*.js";
const execution = yield execute( command );

assert.equal( execution.code, 0 );
Expand Down