Skip to content

Commit

Permalink
Tests: Add structure test to keep suites in sync
Browse files Browse the repository at this point in the history
Bump cli/eslintrc from es2017 to es2018 to allow use of the RegExp `s`
flag (dotAll). This is supported since Node 8+.

Ref #1511.
  • Loading branch information
Krinkle committed Aug 9, 2021
1 parent e453258 commit 32bce94
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 13 deletions.
6 changes: 4 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ module.exports = function( grunt ) {
path.resolve( "./build/coverage-bridge.js" ),
require.resolve( "grunt-contrib-qunit/chrome/bridge" )
],

// @HTML_FILES
urls: [
"test/index.html",

Expand Down Expand Up @@ -118,8 +120,8 @@ module.exports = function( grunt ) {
"test/main/test.js",
"test/main/each.js",
"test/main/assert.js",
"test/main/assert/step.js",
"test/main/assert/timeout.js",
"test/main/assert-step.js",
"test/main/assert-timeout.js",
"test/main/async.js",
"test/main/promise.js",
"test/main/dump.js",
Expand Down
2 changes: 1 addition & 1 deletion test/cli/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"parserOptions": {
"ecmaVersion": 2017
"ecmaVersion": 2018
},
"env": {
"node": true,
Expand Down
78 changes: 78 additions & 0 deletions test/cli/structure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
const fs = require( "fs" );
const glob = require( "tiny-glob/sync" );

// This is a meta test to validate structural expectations of our
// tests, such as checking for fixture files that aren't used or
// missing from one of the test targets.
QUnit.module( "structure", () => {

QUnit.module( "test/main/*.js", () => {
const files = fs.readdirSync( __dirname + "/../main/" )
.map( file => `main/${file}` );

QUnit.test( "files", assert => {
assert.true( files.length > 5, "found files" );
assert.deepEqual(
files.filter( file => file.endsWith( ".js" ) ),
files,
"js files"
);
} );

QUnit.test( "index.html", assert => {
const contents = fs.readFileSync( __dirname + "/../index.html", "utf8" );
files.forEach( file => {
assert.true( contents.includes( file ), file );
} );
} );

QUnit.test( "test-on-node", assert => {
const raw = fs.readFileSync( __dirname + "/../../Gruntfile.js", "utf8" );
const contents = raw.match( /test-on-node.*?\{.*?\}/s )[ 0 ];

files.forEach( file => {
assert.true( contents.includes( file ), file );
} );
} );

QUnit.test( "mozjs", assert => {
const contents = fs.readFileSync( __dirname + "/../mozjs.js", "utf8" );
files.forEach( file => {
assert.true( contents.includes( file ), file );
} );
} );

QUnit.test( "Web Worker", assert => {
const contents = fs.readFileSync( __dirname + "/../webWorker-worker.js", "utf8" );
files.forEach( file => {
assert.true( contents.includes( file ), file );
} );
} );
} );

QUnit.module( "test/**.html", () => {

// Get a list of the HTML files, including in subdirectories (e.g. "test/reporter-html/").
// Ignore file names containing "--", which are subresources (e.g. iframes).
const files = glob( "**/*.html", {
cwd: __dirname + "/../",
filesOnly: true
} )
.filter( file => !file.includes( "--" ) )
.map( file => `test/${file}` );

QUnit.test( "files", assert => {
assert.true( files.length > 5, "found files" );
} );

QUnit.test( "grunt-contrib-qunit", assert => {
const raw = fs.readFileSync( __dirname + "/../../Gruntfile.js", "utf8" );
const contents = raw.match( /@HTML_FILES.*?\[.*?\]/s )[ 0 ];

files.forEach( file => {
assert.true( contents.includes( file ), file );
} );
} );
} );
} );

4 changes: 2 additions & 2 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<script src="main/test.js"></script>
<script src="main/each.js"></script>
<script src="main/assert.js"></script>
<script src="main/assert/step.js"></script>
<script src="main/assert/timeout.js"></script>
<script src="main/assert-step.js"></script>
<script src="main/assert-timeout.js"></script>
<script src="main/async.js"></script>
<script src="main/promise.js"></script>
<script src="main/dump.js"></script>
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions test/mozjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ QUnit.on( "runEnd", ( suiteEnd ) => {
loadRelativeToScript( "../test/main/test.js" );
loadRelativeToScript( "../test/main/each.js" );
loadRelativeToScript( "../test/main/assert.js" );
loadRelativeToScript( "../test/main/assert/step.js" );
// Requires setTimeout, loadRelativeToScript( "../test/main/assert/timeout.js" );
// Requires setTimeout, loadRelativeToScript( "../test/main/async.js" );
loadRelativeToScript( "../test/main/assert-step.js" );
// loadRelativeToScript( "../test/main/assert-timeout.js" ); // Requires setTimeout
// loadRelativeToScript( "../test/main/async.js" ); // Requires setTimeout
loadRelativeToScript( "../test/main/promise.js" );
loadRelativeToScript( "../test/main/dump.js" );
// Requires setTimeout, loadRelativeToScript( "../test/main/modules.js" );
// loadRelativeToScript( "../test/main/modules.js" ); // Requires setTimeout
loadRelativeToScript( "../test/main/deepEqual.js" );
loadRelativeToScript( "../test/main/stack.js" );
loadRelativeToScript( "../test/main/utilities.js" );
Expand Down
2 changes: 1 addition & 1 deletion test/reporter-html/xhtml-escape-details-source.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<title>QUnit Main Test Suite</title>
<link rel="stylesheet" href="../../qunit/qunit.css" />
<script src="../../qunit/qunit.js"></script>
<script src="test-escape-details-source.js"></script>
<script src="xhtml-escape-details-source.js"></script>
</head>
<body>
<div id="qunit"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="UTF-8">
<title>QUnit in Sandboxed Iframe Test Suite - Inside Iframe</title>
<title>sandboxed iframe contents</title>
<link rel="stylesheet" href="../qunit/qunit.css">
<script src="../qunit/qunit.js"></script>
<script src="sandboxed-iframe.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions test/sandboxed-iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<html>
<head>
<meta charset="UTF-8">
<title>QUnit in Sandboxed Iframe Test Suite</title>
<title>sandboxed iframe</title>
</head>
<body>
<iframe src="sandboxed-iframe-contents.html" sandbox="allow-scripts"></iframe>
<iframe src="sandboxed-iframe--contents.html" sandbox="allow-scripts"></iframe>
</body>
</html>

0 comments on commit 32bce94

Please sign in to comment.