mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-01 01:38:07 +08:00
To date the Karma singleRun option has been set based on whether the developer sets the DEBUG environment variable. This CL adds support for an additional REPEAT environment variable, such that someone can run multiple, non-debug (i.e., headless) test runs. In order to make this more convenient, this CL also improves the watcher script (`npm run watch`) such that it restarts autoninja whenever files are changed. Therefore a developer can now run: `REPEAT=1 npm run auto-unittest` and `npm run watch` in conjunction, and have the code be recompiled automatically, and the unit tests (re)started. R=jacktfranklin@chromium.org Change-Id: I8cff9eb7d223a5325e952413ddd5c1f55dd8aec2 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2562709 Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> Commit-Queue: Paul Lewis <aerotwist@chromium.org>
62 lines
2.0 KiB
JavaScript
62 lines
2.0 KiB
JavaScript
// Copyright 2020 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const childProcess = require('child_process');
|
|
const cwd = process.cwd();
|
|
const env = process.env;
|
|
const frontEndDir = path.join(cwd, 'front_end');
|
|
const testsDir = path.join(cwd, 'test');
|
|
|
|
// Extract the target if it's provided.
|
|
let target = 'Default';
|
|
const targetArg = process.argv.find(value => value.startsWith('--target='));
|
|
if (targetArg) {
|
|
target = targetArg.slice('--target='.length);
|
|
}
|
|
|
|
let restartBuild = false;
|
|
let autoninja;
|
|
const changedFiles = new Set();
|
|
const onFileChange = (_, fileName) => {
|
|
// Some filesystems emit multiple events in quick succession for a
|
|
// single file change. Here we track the changed files, and reset
|
|
// after a short timeout.
|
|
if (changedFiles.has(fileName)) {
|
|
return;
|
|
}
|
|
changedFiles.add(fileName);
|
|
setTimeout(() => {
|
|
changedFiles.delete(fileName);
|
|
}, 250);
|
|
|
|
// If the exitCode is null, autoninja is still running so stop it
|
|
// and try to restart it again.
|
|
const ninjaProcessExists = !!(autoninja && autoninja.pid);
|
|
if (ninjaProcessExists) {
|
|
const isRunning = ninjaProcessExists && autoninja.exitCode === null;
|
|
if (isRunning) {
|
|
autoninja.kill();
|
|
restartBuild = true;
|
|
}
|
|
return;
|
|
}
|
|
|
|
autoninja = childProcess.spawn('autoninja', ['-C', `out/${target}`], {cwd, env, stdio: 'inherit'});
|
|
autoninja.on('close', () => {
|
|
autoninja = null;
|
|
if (restartBuild) {
|
|
restartBuild = false;
|
|
console.log(`\n${fileName} changed, restarting ninja\n`);
|
|
onFileChange();
|
|
}
|
|
});
|
|
};
|
|
|
|
// Watch the front_end and test folder and build on any change.
|
|
console.log(`Watching for changes in ${frontEndDir} and ${testsDir}; building to out/${target}`);
|
|
fs.watch(`${frontEndDir}`, {recursive: true}, onFileChange);
|
|
fs.watch(`${testsDir}`, {recursive: true}, onFileChange);
|