Skip to content

Commit

Permalink
Simplify karma.conf by reusing node_module resolution logic via requi…
Browse files Browse the repository at this point in the history
…re.resolve (bazel-contrib#278)
  • Loading branch information
alexeagle authored Sep 19, 2018
1 parent 49ab0d3 commit 5542a1c
Showing 1 changed file with 5 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,50 +64,18 @@ if (!browsers.length) {
browsers.push(process.env['DISPLAY'] ? 'Chrome': 'ChromeHeadless');
}

// On Windows, runfiles will not be in the runfiles folder but inteaad
// there is a MANIFEST file which maps the runfiles for the test
// to their location on disk. Bazel provides a RUNFILE_MANIFEST_FILE environment
// variable which is set the location of the MANIFEST file during test execution.
// If a MANIFEST file is found, we remap the test files to their
// location on disk using the MANIFEST file.
let manifest = null;
if (process.env.RUNFILE_MANIFEST_FILE && fs.existsSync(process.env.RUNFILE_MANIFEST_FILE)) {
// MANIFEST file contains the one runfile mapping per line seperated
// a space. For example:
// rxjs/operators.js /private/var/tmp/.../external/rxjs/operators.js
// The file is parsed here into a map of for easy lookup
manifest = {};
for (l of fs.readFileSync(process.env.RUNFILE_MANIFEST_FILE, 'utf8').split('\n')) {
const m = l.split(' ');
manifest[m[0]] = m[1];
}
}

function resolveRunfiles(manifest, runfiles) {
if (manifest) {
runfiles = runfiles.map(f => {
const manifestFile = manifest[f];
if (!manifestFile) {
throw new Error(`File not found in MANIFEST: ${f}`);
}
return manifestFile;
});
}
return runfiles;
}

const files = resolveRunfiles(manifest, [
const files = [
TMPL_bootstrap_files
TMPL_user_files
]);
].map(f => require.resolve(f));

// static files are added to the files array but
// configured to not be included so karma-concat-js does
// not included them in the bundle
resolveRunfiles(manifest, [
[
TMPL_static_files
]).forEach(f => {
files.push({ pattern: f, included: false });
].forEach(f => {
files.push({ pattern: require.resolve(f), included: false });
});

var requireConfigContent = `
Expand Down

0 comments on commit 5542a1c

Please sign in to comment.