Test sweep (#420)

* Big ole test re-jig

* Current work

* Moving all tests over to the test runner

* Fixing last nits in the build and test runner

* Adding precaching integration tests

* Moving sw-appcache-behavior to integration test

* Adding bg-sync to test suite again - incoming fails

* Fixing the last pieces of the test sweep

* Removing logs

* Removing number of repeats in tests - should be determined by the individual tests - not the runner

* Small move around with sw-appcache

* Retry the end to end-to-end test
This commit is contained in:
Matt Gaunt
2017-04-07 10:59:53 -07:00
committed by Addy Osmani
parent 0342d41e66
commit 1f62f7a2b3
78 changed files with 779 additions and 1456 deletions
+62 -6
View File
@@ -27,6 +27,7 @@ const serveStatic = require('serve-static');
class ServerInstance {
constructor() {
this._server = null;
this._sockets = [];
this._app = express();
this._app.use(cookieParser());
@@ -73,19 +74,66 @@ class ServerInstance {
// Harness to kick off all the in-browser tests for a given package.
// It will pick up a list of all the top-level .js files and automatically
// inject them into the HTML as <script> tags.
this._app.get('/__test/mocha/:pkg', function(req, res) {
this._app.get('/__test/mocha/browser/:pkg', function(req, res) {
const pkg = req.params.pkg;
const pattern = `packages/${pkg}/test/browser/*.js`;
const scripts = glob.sync(pattern).map((script) => `/${script}`);
const repoRoot = path.join(__dirname, '..');
const scripts = glob.sync(pattern, {
cwd: repoRoot,
root: repoRoot,
}).map((script) => {
// Converts packages/<pkg name>/test/sw/<filename>.js
// to /packages/<pkg name>/test/sw/<filename>.js
return `/${script}`;
});
if (scripts.length === 0) {
throw Error(`No test scripts match the pattern '${pattern}'.`);
const errMsg = `No test scripts match the pattern '${pattern}'.`;
/* eslint-disable no-console */
console.log(errMsg);
/* eslint-enable no-console */
res.status(500).send(errMsg);
return;
}
let config = {};
try {
// Read JSON file to avoid the require cache
config =
JSON.parse(
fs.readFileSync(
path.join(__dirname, '..', 'packages', pkg, 'test', 'config.json')
, 'utf-8')
);
} catch (err) {
// NOOP
}
const source = fs.readFileSync(path.join(
__dirname, '..', 'templates', 'test-harness.hbs'), 'utf-8');
__dirname, '..', 'templates', 'test-browser.hbs'), 'utf-8');
const template = handlebars.compile(source);
const html = template({scripts, pkg});
const html = template({
scripts,
config,
pkg,
});
res.send(html);
});
this._app.get('/__test/mocha/sw/:pkg', function(req, res) {
/* eslint-disable no-console */
const pkg = req.params.pkg;
const pattern = `packages/${pkg}/test/sw/*.js`;
const scriptPaths = glob.sync(pattern).map((script) => {
// Converts packages/<pkg name>/test/sw/<filename>.js
// to /packages/<pkg name>/test/sw/<filename>.js
return `/${script}`;
});
const source = fs.readFileSync(path.join(
__dirname, '..', 'templates', 'test-sw.hbs'), 'utf-8');
const template = handlebars.compile(source);
const html = template({scripts: scriptPaths, pkg});
res.send(html);
});
@@ -133,11 +181,19 @@ class ServerInstance {
}
resolve(this._server.address().port);
});
this._server.on('connection', (socket) => {
this._sockets.push(socket);
});
});
}
stop() {
return new Promise((resolve) => {
this._sockets.forEach((socket) => {
socket.destroy();
});
this._server.close(resolve);
this._server = null;
});