From 32bce9421b0186f60c4c74be3788b1e32103a6fd Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Mon, 9 Aug 2021 02:14:33 +0100 Subject: [PATCH] Tests: Add structure test to keep suites in sync Bump cli/eslintrc from es2017 to es2018 to allow use of the RegExp `s` flag (dotAll). This is supported since Node 8+. Ref https://github.com/qunitjs/qunit/issues/1511. --- Gruntfile.js | 6 +- test/cli/.eslintrc.json | 2 +- test/cli/structure.js | 78 +++++++++++++++++++ test/index.html | 4 +- test/main/{assert/step.js => assert-step.js} | 0 .../{assert/timeout.js => assert-timeout.js} | 0 test/mozjs.js | 8 +- ...urce.js => xhtml-escape-details-source.js} | 0 .../xhtml-escape-details-source.xhtml | 2 +- ...s.html => sandboxed-iframe--contents.html} | 2 +- test/sandboxed-iframe.html | 4 +- 11 files changed, 93 insertions(+), 13 deletions(-) create mode 100644 test/cli/structure.js rename test/main/{assert/step.js => assert-step.js} (100%) rename test/main/{assert/timeout.js => assert-timeout.js} (100%) rename test/reporter-html/{test-escape-details-source.js => xhtml-escape-details-source.js} (100%) rename test/{sandboxed-iframe-contents.html => sandboxed-iframe--contents.html} (82%) diff --git a/Gruntfile.js b/Gruntfile.js index e9b821324..f3bf376af 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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", @@ -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", diff --git a/test/cli/.eslintrc.json b/test/cli/.eslintrc.json index c0704a1ff..da21cfbd2 100644 --- a/test/cli/.eslintrc.json +++ b/test/cli/.eslintrc.json @@ -1,6 +1,6 @@ { "parserOptions": { - "ecmaVersion": 2017 + "ecmaVersion": 2018 }, "env": { "node": true, diff --git a/test/cli/structure.js b/test/cli/structure.js new file mode 100644 index 000000000..cc8dbdb70 --- /dev/null +++ b/test/cli/structure.js @@ -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 ); + } ); + } ); + } ); +} ); + diff --git a/test/index.html b/test/index.html index 86e97ce2d..d537c926e 100644 --- a/test/index.html +++ b/test/index.html @@ -9,8 +9,8 @@ - - + + diff --git a/test/main/assert/step.js b/test/main/assert-step.js similarity index 100% rename from test/main/assert/step.js rename to test/main/assert-step.js diff --git a/test/main/assert/timeout.js b/test/main/assert-timeout.js similarity index 100% rename from test/main/assert/timeout.js rename to test/main/assert-timeout.js diff --git a/test/mozjs.js b/test/mozjs.js index a4d9554ca..1f8d7db74 100644 --- a/test/mozjs.js +++ b/test/mozjs.js @@ -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" ); diff --git a/test/reporter-html/test-escape-details-source.js b/test/reporter-html/xhtml-escape-details-source.js similarity index 100% rename from test/reporter-html/test-escape-details-source.js rename to test/reporter-html/xhtml-escape-details-source.js diff --git a/test/reporter-html/xhtml-escape-details-source.xhtml b/test/reporter-html/xhtml-escape-details-source.xhtml index 3528717db..4406427a4 100644 --- a/test/reporter-html/xhtml-escape-details-source.xhtml +++ b/test/reporter-html/xhtml-escape-details-source.xhtml @@ -6,7 +6,7 @@ QUnit Main Test Suite - +
diff --git a/test/sandboxed-iframe-contents.html b/test/sandboxed-iframe--contents.html similarity index 82% rename from test/sandboxed-iframe-contents.html rename to test/sandboxed-iframe--contents.html index 637570513..b140e04aa 100644 --- a/test/sandboxed-iframe-contents.html +++ b/test/sandboxed-iframe--contents.html @@ -2,7 +2,7 @@ - QUnit in Sandboxed Iframe Test Suite - Inside Iframe + sandboxed iframe contents diff --git a/test/sandboxed-iframe.html b/test/sandboxed-iframe.html index 56ba13398..73f0d6a41 100644 --- a/test/sandboxed-iframe.html +++ b/test/sandboxed-iframe.html @@ -2,9 +2,9 @@ - QUnit in Sandboxed Iframe Test Suite + sandboxed iframe - +