Skip to content

Commit

Permalink
chore: Fix jest tests on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Holzer committed Sep 23, 2020
1 parent ea7c3f4 commit 72f29e1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 61 deletions.
2 changes: 2 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ npm_install(
data = [
"//:patches/@angular+bazel+10.0.6.patch",
"//:patches/@bazel+typescript+2.0.3.patch",
"//:patches/jest-haste-map+26.1.0.patch",
"//:patches/stylelint+13.2.1.patch",
"//:postinstall.js",
"//:view-engine-tsconfig.json"
],
Expand Down
16 changes: 16 additions & 0 deletions patches/jest-haste-map+26.1.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/node_modules/jest-haste-map/build/crawlers/node.js b/node_modules/jest-haste-map/build/crawlers/node.js
index 6b6e11a..2ff08fa 100644
--- a/node_modules/jest-haste-map/build/crawlers/node.js
+++ b/node_modules/jest-haste-map/build/crawlers/node.js
@@ -205,7 +205,11 @@ function find(roots, extensions, ignore, callback) {

function findNative(roots, extensions, ignore, callback) {
const args = Array.from(roots);
+ args.push('(');
args.push('-type', 'f');
+ args.push('-o');
+ args.push('-type', 'l');
+ args.push(')');

if (extensions.length) {
args.push('(');
9 changes: 7 additions & 2 deletions tools/bazel_rules/jest/jest-resolver.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
const { sync } = require('resolve');
const { readFileSync, existsSync, lstatSync } = require('fs');
const { resolve } = require('path');
const { resolve, join } = require('path');

// Get the module mappings out of the module mappings file from bazel
const moduleMappingFile = process.env.BAZEL_TEST_MODULE_MAPPING;
const [bazelPackage, bazelTarget] = process.env.BAZEL_TARGET.split(':');
const moduleMappingFile = join(
bazelPackage.replace('//', ''),
`_${bazelTarget}.module_mappings.json`,
);

// bazel run files helper used to resolve paths that are created with `$(location ...)`
const runFilesHelper = require(`${process.env.BAZEL_NODE_RUNFILES_HELPER}`);

Expand Down
85 changes: 26 additions & 59 deletions tools/bazel_rules/jest/jest-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const { argv } = require('yargs');

// Path of the test.sh binary that gets created from the nodejs_test
const { TEST_BINARY } = process.env;
// Bazels node runfiles helper
const RUNFILES_HELPER = require(process.env.BAZEL_NODE_RUNFILES_HELPER);

/**
* Updates the jest config json with additional properties
Expand Down Expand Up @@ -48,68 +50,33 @@ function updateJestConfig(suiteName, config = undefined) {
async function main() {
const { jestConfig, setupFile, files, suite } = argv;
const jestConfigPath = updateJestConfig(suite, jestConfig);
const base = dirname(jestConfigPath);

const helper = require(process.env.BAZEL_NODE_RUNFILES_HELPER);
// console.log(helper.__proto__)
// console.dir(helper.loadRunfilesManifest(helper.manifest))
// console.log(process.env)
console.log(process.argv.slice(2));

const asdf = files
.split(',')
.map((source) => join(base, source).replace(/ts$/, 'js'));

console.log(Object.keys(helper));

console.log(`
-------------------------
${process.cwd()}
${jestConfig}
${setupFile}
Files: ${asdf}
${suite}
MANIFEST: ${process.env.RUNFILES_MANIFEST_FILE}
WORKSPACE: ${process.env.BAZEL_WORKSPACE} | ${helper.workspace}
TARGET: ${process.env.BAZEL_TARGET}
Package: ${helper.package}
${join(dirname(TEST_BINARY), `_${suite}.module_mappings.json`)}
`);

process.exit(1);

process.env.BAZEL_TEST_MODULE_MAPPING = join(
dirname(TEST_BINARY),
`_${suite}.module_mappings.json`,
);

const resolvedFiles = files
.split(',')
.map((source) => join(base, source).replace(/ts$/, 'js'));

const cliArgs = {
/**
* This is a hack to avoid using the jest-haste-map fs that does not support symbolic links
* https://github.com/facebook/metro/issues/1#issuecomment-641633646
*/
_: resolvedFiles,
runTestsByPath: true,
verbose: true,
resolver: resolve('tools/bazel_rules/jest/jest-resolver.js'),
rootDir: resolve('./'),
colors: false,
};

if (setupFile) {
cliArgs.setupFilesAfterEnv = [resolve(setupFile).replace(/ts$/, 'js')];
}

const { results } = await runCLI(cliArgs, [jestConfigPath]);
.map((source) =>
join(RUNFILES_HELPER.package, source).replace(/ts$/, 'js'),
);

const { results } = await runCLI(
{
/**
* This is a hack to avoid using the jest-haste-map fs that does not support symbolic links
* https://github.com/facebook/metro/issues/1#issuecomment-641633646
*/
_: resolvedFiles,
setupFilesAfterEnv: setupFile
? [resolve(setupFile).replace(/ts$/, 'js')]
: [],
runTestsByPath: true,
verbose: true,
expand: true,
cache: false,
resolver: resolve('tools/bazel_rules/jest/jest-resolver.js'),
rootDir: resolve('./'), //resolve(helper.package),
colors: true,
},
[jestConfigPath],
);

if (!results.success) {
throw new Error(`Failed executing jest tests`);
Expand Down

0 comments on commit 72f29e1

Please sign in to comment.