diff options
author | Timmy Willison <timmywil@users.noreply.github.com> | 2024-03-29 09:13:46 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-29 09:13:46 -0400 |
commit | 91df20be6b488ac6cf4da291d7ee3aa5d6feac73 (patch) | |
tree | 56b5c4f8b96a8323e3a6ce9c02c3e84c85a9d6d5 /tests/runner/createTestServer.js | |
parent | 802642c37323d5fc05bfa4cee90a900953f9a98d (diff) | |
download | jquery-ui-91df20be6b488ac6cf4da291d7ee3aa5d6feac73.tar.gz jquery-ui-91df20be6b488ac6cf4da291d7ee3aa5d6feac73.zip |
Tests: replace grunt-contrib-qunit with jQuery test runner
- add filestash workflow
Close gh-2221
Diffstat (limited to 'tests/runner/createTestServer.js')
-rw-r--r-- | tests/runner/createTestServer.js | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/runner/createTestServer.js b/tests/runner/createTestServer.js new file mode 100644 index 000000000..878aa7d83 --- /dev/null +++ b/tests/runner/createTestServer.js @@ -0,0 +1,66 @@ +import bodyParser from "body-parser"; +import express from "express"; +import bodyParserErrorHandler from "express-body-parser-error-handler"; +import { readFile } from "node:fs/promises"; + +export async function createTestServer( report ) { + const app = express(); + + // Redirect home to test page + app.get( "/", ( _req, res ) => { + res.redirect( "/tests/" ); + } ); + + // Redirect to trailing slash + app.use( ( req, res, next ) => { + if ( req.path === "/tests" ) { + const query = req.url.slice( req.path.length ); + res.redirect( 301, `${ req.path }/${ query }` ); + } else { + next(); + } + } ); + + // Add a script tag to HTML pages to load the QUnit listeners + app.use( /\/tests\/unit\/([^/]+)\/\1\.html$/, async( req, res ) => { + const html = await readFile( + `tests/unit/${ req.params[ 0 ] }/${ req.params[ 0 ] }.html`, + "utf8" + ); + res.send( + html.replace( + "</head>", + "<script src=\"/tests/runner/listeners.js\"></script></head>" + ) + ); + } ); + + // Bind the reporter + app.post( + "/api/report", + bodyParser.json( { limit: "50mb" } ), + async( req, res ) => { + if ( report ) { + const response = await report( req.body ); + if ( response ) { + res.json( response ); + return; + } + } + res.sendStatus( 204 ); + } + ); + + // Handle errors from the body parser + app.use( bodyParserErrorHandler() ); + + // Serve static files + app.use( "/dist", express.static( "dist" ) ); + app.use( "/src", express.static( "src" ) ); + app.use( "/tests", express.static( "tests" ) ); + app.use( "/ui", express.static( "ui" ) ); + app.use( "/themes", express.static( "themes" ) ); + app.use( "/external", express.static( "external" ) ); + + return app; +} |