Skip to content

Commit bea9feb

Browse files
committed
Tests: Enable test/main/promise.js in mozjs CI job
It just had one inline call to setTimeout in one of the test cases, which is easily changed to use our local `defer` function instead. After that, it passed. While at it, simplify and synchronise the two mock-promise functions. Not yet worth abstracting I think, but thinking about it. Ref #1511.
1 parent 0c2bb7f commit bea9feb

4 files changed

Lines changed: 34 additions & 21 deletions

File tree

.github/workflows/CI.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ jobs:
6565
- name: Tests
6666
run: ${{ matrix.script }}
6767

68+
# To reproduce SpiderMonkey builds locally:
69+
#
70+
# 1. Run the build the same way you normally do.
71+
# ```
72+
# nobody@nodejs-isolated:/qunit$ npm run build
73+
# ```
74+
# 2. Start a temporary Docker container using the official Ubuntu image from DockerHub,
75+
# and mount the current working directory in it:
76+
# ```
77+
# you@host:/qunit$ MNT=$(basename "$PWD"); docker run --rm --interactive --tty --mount type=bind,source="$PWD",target="/$MNT",readonly --entrypoint /bin/sh ubuntu:focal -c "cd /$MNT;bash"
78+
# ```
79+
# 3. Run the following from the Docker container's bash prompt:
80+
# ```
81+
# root@ubuntu-tmp/qunit$ apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y libmozjs-68-dev
82+
# root@ubuntu-tmp/qunit$ js68 test/mozjs.js
83+
# ```
84+
#
6885
sm-test:
6986
name: SpiderMonkey
7087
runs-on: ubuntu-20.04

test/main/assert.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
function buildMockPromise( settledValue, shouldFulfill ) {
22

3-
// Support IE 9: Promise not supported, test should not load polyfil globally to ensure
4-
// QUnit works without it, so we create our own thenable with setTimeout.
5-
// Support SpiderMonkey: setTimeout is not supported, re-use the IE 9 mock, but
6-
// using SM's native Promise support for the deferred callback handling.
7-
var defer = typeof setTimeout !== "undefined" ?
8-
setTimeout :
9-
function( fn ) {
10-
Promise.resolve().then( fn );
11-
};
3+
// Support IE 9: Promise not supported, test MUST NOT load polyfil globally.
4+
// Support SpiderMonkey: setTimeout is not supported, but native Promise is.
5+
var defer = typeof setTimeout !== "undefined" ? setTimeout : function( fn ) {
6+
Promise.resolve().then( fn );
7+
};
128

13-
// Return a mock self-fulfilling Promise ("thenable")
149
var thenable = {
1510
then: function( fulfilledCallback, rejectedCallback ) {
1611
defer( function() {
@@ -19,12 +14,10 @@ function buildMockPromise( settledValue, shouldFulfill ) {
1914
rejectedCallback.call( thenable, settledValue );
2015
} );
2116

22-
// returning another thennable for easy confirmation
23-
// of return value
17+
// returning another thenable for easy confirmation of return value
2418
return buildMockPromise( "final promise", true );
2519
}
2620
};
27-
2821
return thenable;
2922
}
3023

test/main/promise.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1+
// Support IE 9: Promise not supported, test MUST NOT load polyfil globally.
2+
// Support SpiderMonkey: setTimeout is not supported, but native Promise is.
3+
var defer = typeof setTimeout !== "undefined" ? setTimeout : function( fn ) {
4+
Promise.resolve().then( fn );
5+
};
6+
17
// NOTE: Adds 1 assertion
28
function createMockPromise( assert, reject, value ) {
39
if ( arguments.length < 3 ) {
410
value = {};
511
}
6-
7-
// Return a mock self-fulfilling Promise ("thenable")
812
var thenable = {
913
then: function( fulfilledCallback, rejectedCallback ) {
10-
assert.strictEqual( this, thenable, "`then` was invoked with the Promise as the " +
11-
"context" );
12-
setTimeout( function() {
14+
assert.strictEqual( this, thenable, "`then` invoked with our Promise as thisValue" );
15+
defer( function() {
1316
return reject ?
1417
rejectedCallback.call( thenable, value ) :
1518
fulfilledCallback.call( thenable, value );
@@ -150,10 +153,10 @@ QUnit.module( "Support for Promise", function() {
150153
assert.expect( 2 );
151154

152155
var done = assert.async();
153-
setTimeout( function() {
156+
defer( function() {
154157
assert.true( true );
155158
done();
156-
}, 100 );
159+
} );
157160

158161
// Adds 1 assertion
159162
return createMockPromise( assert );

test/mozjs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ loadRelativeToScript( "../test/main/assert.js" );
4343
loadRelativeToScript( "../test/main/assert/step.js" );
4444
// Requires setTimeout, loadRelativeToScript( "../test/main/assert/timeout.js" );
4545
// Requires setTimeout, loadRelativeToScript( "../test/main/async.js" );
46-
// Requires setTimeout, loadRelativeToScript( "../test/main/promise.js" );
46+
loadRelativeToScript( "../test/main/promise.js" );
4747
loadRelativeToScript( "../test/main/dump.js" );
4848
// Requires setTimeout, loadRelativeToScript( "../test/main/modules.js" );
4949
loadRelativeToScript( "../test/main/deepEqual.js" );

0 commit comments

Comments
 (0)