Skip to content

Commit

Permalink
run qunit test suite without gulp
Browse files Browse the repository at this point in the history
  • Loading branch information
hakimel committed Oct 17, 2024
1 parent 6b7698d commit a4b53c6
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 41 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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",
Expand Down
67 changes: 67 additions & 0 deletions test.cjs
Original file line number Diff line number Diff line change
@@ -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);
}
})();
76 changes: 37 additions & 39 deletions test/test-iframes.html
Original file line number Diff line number Diff line change
Expand Up @@ -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' );

});

} );
});
</script>

</body>
Expand Down

0 comments on commit a4b53c6

Please sign in to comment.