Skip to content

Commit

Permalink
tests/perf: add cross-origin isolation for more precise measurement
Browse files Browse the repository at this point in the history
See: https://developer.mozilla.org/en-US/docs/Web/API/Performance/now#security_requirements

This requires a change of dependencies from http-server to serve as http-server does not currently support setting the required headers.  See:

* http-party/http-server#759
* http-party/http-server#806
  • Loading branch information
alxndrsn committed Apr 2, 2024
1 parent df73502 commit 083adc2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions bin/dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

'use strict';

const http = require('http');
var watch = require('watch-glob');
var http_server = require('http-server');
const serveHandler = require('serve-handler');
var debounce = require('lodash.debounce');
var browserify = require('browserify');
var fs = require('fs');
Expand Down Expand Up @@ -92,7 +93,15 @@ var readyCallback;

function startServers(callback) {
readyCallback = callback;
http_server.createServer().listen(HTTP_PORT, function () {
const server = http.createServer((req, res) => {
// Add cross-origin isolation headers to allow for more precise performance measurements.
// See: https://developer.mozilla.org/en-US/docs/Web/API/Performance/now#security_requirements
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp');

return serveHandler(req, res, { trailingSlash:true });
});
server.listen(HTTP_PORT, () => {
var testRoot = 'http://127.0.0.1:' + HTTP_PORT;
const query = new URLSearchParams(queryParams);
console.log(`Integration tests: ${testRoot}/tests/integration/?${query}`);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
"express-pouchdb": "4.2.0",
"find-requires": "1.0.0",
"glob": "7.1.5",
"http-server": "0.12.3",
"istanbul": "0.4.5",
"istanbul-coveralls": "1.0.3",
"less": "3.9.0",
Expand All @@ -99,6 +98,7 @@
"rollup-plugin-node-resolve": "4.2.4",
"rollup-plugin-replace": "1.2.1",
"seedrandom": "3.0.5",
"serve-handler": "6.1.5",
"source-map": "0.7.4",
"stacktrace-parser": "0.1.10",
"stream-to-promise": "1.1.1",
Expand Down

0 comments on commit 083adc2

Please sign in to comment.