Skip to content

Commit

Permalink
Tests: Clean up and expand coverage of testId, moduleId, module config
Browse files Browse the repository at this point in the history
* Focus `reporter-html/config-*` just on what the HTML Reporter
  does.

* Add `cli/fixture/config-*` for the general behaviour.

* Add `urlparams-*` for the end-to-end behaviour from a real URL
  parameter, parsing it, and applying the config.
  • Loading branch information
Krinkle committed Sep 19, 2021
1 parent eda94ca commit 87c1f9f
Show file tree
Hide file tree
Showing 19 changed files with 263 additions and 138 deletions.
9 changes: 5 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ module.exports = function( grunt ) {
"test/events-in-test.html",
"test/headless.html",
"test/logs.html",
"test/module-filter.html",
"test/module-skip.html",
"test/module-todo.html",
"test/moduleId.html",
"test/only-each.html",
"test/overload.html",
"test/performance-mark.html",
Expand All @@ -98,15 +96,18 @@ module.exports = function( grunt ) {
"test/seed.html",
"test/startError.html",
"test/string-filter.html",
"test/urlparams-module.html",
"test/urlparams-moduleId.html",
"test/urlparams-testId.html",
"test/webWorker.html",

"test/reporter-html/legacy-markup.html",
"test/reporter-html/no-qunit-element.html",
"test/reporter-html/single-testid.html",
"test/reporter-html/config-testId.html",
"test/reporter-html/window-onerror-preexisting-handler.html",
"test/reporter-html/window-onerror.html",
"test/reporter-html/xhtml-escape-details-source.xhtml",
"test/reporter-html/xhtml-single-testid.xhtml"
"test/reporter-html/xhtml-config-testid.xhtml"

].map( file => `http://localhost:${connectPort}/${file}` )
}
Expand Down
18 changes: 18 additions & 0 deletions test/cli/cli-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,24 @@ CALLBACK: done`;
assert.equal( execution.stdout, expectedOutput[ command ] );
} );

QUnit.test( "config.moduleId", async assert => {
const command = "qunit config-moduleId.js";
const execution = await execute( command );

assert.equal( execution.code, 0 );
assert.equal( execution.stderr, "" );
assert.equal( execution.stdout, expectedOutput[ command ] );
} );

QUnit.test( "config.testId", async assert => {
const command = "qunit config-testId.js";
const execution = await execute( command );

assert.equal( execution.code, 0 );
assert.equal( execution.stderr, "" );
assert.equal( execution.stdout, expectedOutput[ command ] );
} );

QUnit.test( "config.testTimeout", async assert => {
const command = "qunit config-testTimeout.js";

Expand Down
4 changes: 2 additions & 2 deletions test/cli/fixtures/config-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ QUnit.config.module = "MODULE b";

QUnit.module( "Module A", () => {
QUnit.test( "Test A", assert => {
assert.true( false ); // fail if hit
assert.true( false );
} );
} );

Expand All @@ -14,6 +14,6 @@ QUnit.module( "Module B", () => {

QUnit.module( "Module C", () => {
QUnit.test( "Test C", assert => {
assert.true( false ); // fail if hit
assert.true( false );
} );
} );
53 changes: 53 additions & 0 deletions test/cli/fixtures/config-moduleId.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
QUnit.config.moduleId = [ "127c21dd", "c1d6ebd4", "7d89af3b" ];

QUnit.test( "global test", function( assert ) {
assert.true( false );
} );

QUnit.module( "module A scoped", function() {
QUnit.test( "test A1", function( assert ) {
assert.true( false );
} );

QUnit.module( "module B nested", function() {
QUnit.test( "test B1", function( assert ) {
assert.true( false );
} );
} );

QUnit.module( "module C nested", function() {
QUnit.test( "test C1", function( assert ) {
assert.true( true, "run module C" );
} );
} );

QUnit.test( "test A2", function( assert ) {
assert.true( false );
} );
} );

QUnit.module( "module D scoped", function() {
QUnit.test( "test D1", function( assert ) {
assert.true( true, "run module D" );
} );

QUnit.module( "module E nested", function() {
QUnit.test( "test E1", function( assert ) {
assert.true( true, "run module D" );
} );
} );

QUnit.test( "test D2", function( assert ) {
assert.true( true, "run module D" );
} );
} );

QUnit.module( "module E flat" );
QUnit.test( "test E1", function( assert ) {
assert.true( false );
} );

QUnit.module( "module F flat" );
QUnit.test( "test F1", function( assert ) {
assert.true( true, "run module F" );
} );
44 changes: 44 additions & 0 deletions test/cli/fixtures/config-testId.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
QUnit.config.testId = [ "94e5e740", "9e89c63c", "066af31c", "c7ae85af" ];

QUnit.test( "test 1", function( assert ) {
assert.true( false );
} );

QUnit.test( "test 2", function( assert ) {
assert.true( true, "run global test 2" );
} );

QUnit.module( "module A", function() {
QUnit.test( "test 1", function( assert ) {
assert.true( false );
} );

QUnit.module( "module B", function() {
QUnit.test( "test 1", function( assert ) {
assert.true( true, "run AB test 1" );
} );
} );

QUnit.module( "module C", function() {
QUnit.test( "test 1", function( assert ) {
assert.true( false );
} );
QUnit.test( "test 2", function( assert ) {
assert.true( true, "run AC test 2" );
} );
} );

QUnit.test( "test 2", function( assert ) {
assert.true( false );
} );
} );

QUnit.test( "test 3", function( assert ) {
assert.true( false );
} );

QUnit.module( "module D", function() {
QUnit.test( "test 1", function( assert ) {
assert.true( true, "run D test 1" );
} );
} );
25 changes: 25 additions & 0 deletions test/cli/fixtures/expected/tap-outputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,31 @@ ok 1 Module B > Test B
# pass 1
# skip 0
# todo 0
# fail 0`,

"qunit config-moduleId.js":
`TAP version 13
ok 1 module A scoped > module C nested > test C1
ok 2 module D scoped > test D1
ok 3 module D scoped > module E nested > test E1
ok 4 module D scoped > test D2
ok 5 module F flat > test F1
1..5
# pass 5
# skip 0
# todo 0
# fail 0`,

"qunit config-testId.js":
`TAP version 13
ok 1 test 2
ok 2 module A > module B > test 1
ok 3 module A > module C > test 2
ok 4 module D > test 1
1..0
# pass 0
# skip 0
# todo 0
# fail 0`,

"qunit config-testTimeout.js":
Expand Down
13 changes: 0 additions & 13 deletions test/module-filter.html

This file was deleted.

55 changes: 0 additions & 55 deletions test/module-filter.js

This file was deleted.

13 changes: 0 additions & 13 deletions test/moduleId.html

This file was deleted.

45 changes: 0 additions & 45 deletions test/moduleId.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<html>
<head>
<meta charset="UTF-8">
<title>QUnit Main Test Suite</title>
<title>QUnit</title>
<link rel="stylesheet" href="../../qunit/qunit.css">
<script src="../../qunit/qunit.js"></script>
<script src="single-testid.js"></script>
</head>
<body>
<div id="qunit"></div>
<script src="../../qunit/qunit.js"></script>
<script src="config-testId.js"></script>
</body>
</html>
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<html xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8" />
<title>QUnit Main Test Suite</title>
<title>QUnit</title>
<link rel="stylesheet" href="../../qunit/qunit.css" />
<script src="../../qunit/qunit.js"></script>
<script src="single-testid.js"></script>
</head>
<body>
<div id="qunit"></div>
<script src="../../qunit/qunit.js"></script>
<script src="config-testId.js"></script>
</body>
</html>
13 changes: 13 additions & 0 deletions test/urlparams-module.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>QUnit</title>
<link rel="stylesheet" href="../qunit/qunit.css">
</head>
<body>
<div id="qunit"></div>
<script src="../qunit/qunit.js"></script>
<script src="urlparams-module.js"></script>
</body>
</html>
16 changes: 16 additions & 0 deletions test/urlparams-module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
if ( !location.search ) {
location.replace( "?module=Foo" );
}

QUnit.module( "Foo" );

QUnit.test( "Foo test", function( assert ) {
assert.true( true, "run module Foo" );
assert.strictEqual( QUnit.config.module, "Foo", "parsed config" );
} );

QUnit.module( "Bar" );

QUnit.test( "Bar test", function( assert ) {
assert.true( false );
} );
Loading

0 comments on commit 87c1f9f

Please sign in to comment.