diff --git a/package.json b/package.json index 1fb93879341..e53a78cd6a9 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "dev": "vite --port 8000", "build:core": "tsc && vite build && vite build -c vite.config.styles.ts", "build": "tsc && vite build && vite build -c vite.config.styles.ts && vite build -c plugin/highlight/vite.config.ts && vite build -c plugin/markdown/vite.config.ts && vite build -c plugin/math/vite.config.ts && vite build -c plugin/notes/vite.config.ts && vite build -c plugin/search/vite.config.ts && vite build -c plugin/zoom/vite.config.ts", - "test": "gulp test", + "test": "node test.cjs", "start": "vite --port 8000" }, "author": { @@ -90,7 +90,7 @@ "gulp-zip": "^5.1.0", "highlight.js": "^11.9.0", "marked": "^4.3.0", - "node-qunit-puppeteer": "^2.1.2", + "node-qunit-puppeteer": "^2.2.0", "qunit": "^2.20.0", "rollup": "^4.1.5", "sass": "^1.69.5", diff --git a/test.cjs b/test.cjs new file mode 100644 index 00000000000..844999d92c6 --- /dev/null +++ b/test.cjs @@ -0,0 +1,67 @@ +const path = require("path"); +const glob = require("glob"); +const { runQunitPuppeteer, printFailedTests, printOutput } = require("node-qunit-puppeteer"); +const { createServer } = require('vite'); + +const testFiles = glob.sync('test/*.html'); + +const combinedResults = { passed: 0, failed: 0, total: 0, runtime: 0 }; + +// Create and start Vite server +const startServer = async () => { + const server = await createServer({ + root: __dirname, + server: { + port: 8009, + }, + }); + await server.listen(); + return server; +}; + +// Run tests +const runTests = async (server) => { + await Promise.all(testFiles.map(async (file) => { + const qunitArgs = { + targetUrl: `http://localhost:8009/${file}`, + timeout: 30000, + redirectConsole: false, + puppeteerArgs: ['--allow-file-access-from-files'] + }; + + try { + const result = await runQunitPuppeteer(qunitArgs); + combinedResults.passed += result.stats.passed; + combinedResults.failed += result.stats.failed; + combinedResults.total += result.stats.total; + combinedResults.runtime += result.stats.runtime; + + if (result.stats.failed > 0) { + console.log(`${'!'} ${file} [${result.stats.passed}/${result.stats.total}] in ${result.stats.runtime}ms`.red); + printFailedTests(result, console); + } + else { + console.log(`${'✔'} ${file} [${result.stats.passed}/${result.stats.total}] in ${result.stats.runtime}ms`.green); + } + } catch (error) { + console.error(`Error running tests for ${file}:`, error); + } + })); + + console.log(`\n${combinedResults.failed}/${combinedResults.total} tests failed, ${combinedResults.runtime}ms runtime`); + + // Exit with status code 1 if any tests failed, otherwise exit with 0 + process.exit(combinedResults.failed > 0 ? 1 : 0); +}; + +// Main execution +(async () => { + try { + const server = await startServer(); + await runTests(server); + await server.close(); + } catch (error) { + console.error('An error occurred:', error); + process.exit(1); + } +})(); diff --git a/test/test-iframes.html b/test/test-iframes.html index fa4b434f431..95d5e52aa07 100644 --- a/test/test-iframes.html +++ b/test/test-iframes.html @@ -36,68 +36,66 @@ QUnit.config.testTimeout = 30000; - Reveal.initialize({ viewDistance: 2 }).then( () => { + Reveal.initialize({ viewDistance: 2 }); - var defaultIframe = document.querySelector( '.default-iframe' ), + var defaultIframe = document.querySelector( '.default-iframe' ), preloadIframe = document.querySelector( '.preload-iframe' ); - QUnit.module( 'Iframe' ); + QUnit.module( 'Iframe' ); - QUnit.test( 'Using default settings', function( assert ) { + QUnit.test( 'Using default settings', function( assert ) { - Reveal.slide(1); - assert.strictEqual( defaultIframe.hasAttribute( 'src' ), false, 'not preloaded when within viewDistance' ); + Reveal.slide(1); + assert.strictEqual( defaultIframe.hasAttribute( 'src' ), false, 'not preloaded when within viewDistance' ); - Reveal.slide(2); - assert.strictEqual( defaultIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' ); + Reveal.slide(2); + assert.strictEqual( defaultIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' ); - Reveal.slide(1); - assert.strictEqual( defaultIframe.hasAttribute( 'src' ), false, 'unloaded when slide becomes invisible' ); + Reveal.slide(1); + assert.strictEqual( defaultIframe.hasAttribute( 'src' ), false, 'unloaded when slide becomes invisible' ); - }); + }); - QUnit.test( 'Using data-preload', function( assert ) { + QUnit.test( 'Using data-preload', function( assert ) { - Reveal.slide(1); - assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'preloaded within viewDistance' ); + Reveal.slide(1); + assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'preloaded within viewDistance' ); - Reveal.slide(2); - assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'loaded when slide becoems visible' ); + Reveal.slide(2); + assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'loaded when slide becoems visible' ); - Reveal.slide(0); - assert.strictEqual( preloadIframe.hasAttribute( 'src' ), false, 'unloads outside of viewDistance' ); + Reveal.slide(0); + assert.strictEqual( preloadIframe.hasAttribute( 'src' ), false, 'unloads outside of viewDistance' ); - }); + }); - QUnit.test( 'Using preloadIframes: true', function( assert ) { + QUnit.test( 'Using preloadIframes: true', function( assert ) { - Reveal.configure({ preloadIframes: true }); + Reveal.configure({ preloadIframes: true }); - Reveal.slide(1); - assert.strictEqual( defaultIframe.hasAttribute( 'src' ), true, 'preloaded within viewDistance' ); - assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'preloaded within viewDistance' ); + Reveal.slide(1); + assert.strictEqual( defaultIframe.hasAttribute( 'src' ), true, 'preloaded within viewDistance' ); + assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'preloaded within viewDistance' ); - Reveal.slide(2); - assert.strictEqual( defaultIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' ); - assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' ); + Reveal.slide(2); + assert.strictEqual( defaultIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' ); + assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' ); - }); + }); - QUnit.test( 'Using preloadIframes: false', function( assert ) { + QUnit.test( 'Using preloadIframes: false', function( assert ) { - Reveal.configure({ preloadIframes: false }); + Reveal.configure({ preloadIframes: false }); - Reveal.slide(0); - assert.strictEqual( defaultIframe.hasAttribute( 'src' ), false, 'not preloaded within viewDistance' ); - assert.strictEqual( preloadIframe.hasAttribute( 'src' ), false, 'not preloaded within viewDistance' ); + Reveal.slide(0); + assert.strictEqual( defaultIframe.hasAttribute( 'src' ), false, 'not preloaded within viewDistance' ); + assert.strictEqual( preloadIframe.hasAttribute( 'src' ), false, 'not preloaded within viewDistance' ); - Reveal.slide(2); - assert.strictEqual( defaultIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' ); - assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' ); + Reveal.slide(2); + assert.strictEqual( defaultIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' ); + assert.strictEqual( preloadIframe.hasAttribute( 'src' ), true, 'loaded when slide becomes visible' ); - }); - - } ); + });