Skip to content

Commit cde5fd3

Browse files
simonbuchanrotemmiz
authored andcommitted
Running on windows support (#628)
* Update package scripts to use node for cross-plattform. * Fix detox test / run-server using paths that don't work on windows. * Replace CRLFs in exec.js, fixes running the emulator on windows. * Should fix build.js on mac. * Remove some paranoia. * Make eslint pass on JS scripts. * Ignore exec hack in coverage to get CI passing. * Walk back detox test change so it works with detox-cli. * Don't try to start emulator if it's already running. * Remove unneeded comments, only refresh ADB devices if needed. * Update detox unit tests to pass on windows. Use path module in tests to normalize paths. Use process.platform to test with actual absolute paths on windows. * Add windows support to detox-cli. * Some basic documentation in roadmap. * docs: 'detox' -> 'Detox' * More docs fixes. * Oops, missed building Detox-ios-src.tbz * Lint complained about hashbangs in detox scripts.
1 parent 74736d6 commit cde5fd3

File tree

16 files changed

+132
-72
lines changed

16 files changed

+132
-72
lines changed

detox-cli/cli.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env node
2+
const cp = require('child_process');
3+
const path = require('path');
4+
const fs = require('fs');
5+
6+
const detoxPath = path.join(process.cwd(), 'node_modules/detox');
7+
const detoxPackageJsonPath = path.join(detoxPath, 'package.json');
8+
9+
if (fs.existsSync(detoxPackageJsonPath)) {
10+
// { shell: true } option seems to break quoting on windows? Otherwise this would be much simpler.
11+
if (process.platform === 'win32') {
12+
const result = cp.spawnSync(
13+
'cmd',
14+
['/c', path.join(process.cwd(), 'node_modules/.bin/detox.cmd')].concat(process.argv.slice(2)),
15+
{ stdio: 'inherit' });
16+
process.exit(result.status);
17+
} else {
18+
const result = cp.spawnSync(
19+
path.join(process.cwd(), 'node_modules/.bin/detox'),
20+
process.argv.slice(2),
21+
{ stdio: 'inherit' });
22+
process.exit(result.status);
23+
}
24+
} else {
25+
console.log(detoxPackageJsonPath);
26+
console.log("detox is not installed in this directory");
27+
process.exit(1);
28+
}

detox-cli/cli.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

detox-cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"test": ":"
88
},
99
"bin": {
10-
"detox": "./cli.sh"
10+
"detox": "./cli.js"
1111
},
1212
"repository": {
1313
"type": "git",

detox/local-cli/detox-run-server.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22

33
const program = require('commander');
44
const cp = require('child_process');
5-
const fs = require('fs');
65
const path = require('path');
76

87
program.parse(process.argv);
98

10-
if (fs.existsSync(path.join(process.cwd(), 'node_modules/.bin/detox-server'))) {
11-
cp.execSync('node_modules/.bin/detox-server', {stdio: 'inherit'});
12-
} else {
13-
cp.execSync('node_modules/detox/node_modules/.bin/detox-server', {stdio: 'inherit'});
14-
}
15-
9+
const serverPackagePath = require.resolve('detox-server/package.json');
10+
const cli = require(serverPackagePath).bin['detox-server'];
11+
const binPath = path.join(path.dirname(serverPackagePath), cli);
12+
cp.execFileSync('node', [binPath], {stdio: 'inherit'});

detox/local-cli/detox-test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,19 @@ function runMocha() {
9999
const headless = program.headless ? `--headless` : '';
100100

101101
const debugSynchronization = program.debugSynchronization ? `--debug-synchronization ${program.debugSynchronization}` : '';
102-
const command = `node_modules/.bin/mocha ${testFolder} ${configFile} ${configuration} ${loglevel} ${cleanup} ${reuse} ${debugSynchronization} ${platformString} ${artifactsLocation} ${headless}`;
102+
const binPath = path.join('node_modules', '.bin', 'mocha');
103+
const command = `${binPath} ${testFolder} ${configFile} ${configuration} ${loglevel} ${cleanup} ${reuse} ${debugSynchronization} ${platformString} ${artifactsLocation} ${headless}`;
103104

104105
console.log(command);
105106
cp.execSync(command, {stdio: 'inherit'});
106107
}
107108

108109
function runJest() {
109110
const configFile = runnerConfig ? `--config=${runnerConfig}` : '';
111+
const platform = program.platform ? `--testNamePattern='^((?!${getPlatformSpecificString(program.platform)}).)*$'` : '';
112+
const binPath = path.join('node_modules', '.bin', 'jest');
110113
const platformString = platform ? `--testNamePattern='^((?!${getPlatformSpecificString(platform)}).)*$'` : '';
111-
const command = `node_modules/.bin/jest ${testFolder} ${configFile} --runInBand ${platformString}`;
114+
const command = `${binPath} ${testFolder} ${configFile} --runInBand ${platformString}`;
112115
console.log(command);
113116
cp.execSync(command, {
114117
stdio: 'inherit',

detox/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
"author": "Tal Kol <talkol@gmail.com>",
2222
"license": "MIT",
2323
"scripts": {
24-
"build": "scripts/build.sh",
25-
"lint": "eslint src",
24+
"build": "node scripts/build.js",
25+
"lint": "eslint src scripts",
2626
"unit": "jest --coverage --verbose",
2727
"pretest": "npm run lint",
2828
"test": "npm run unit",
2929
"unit:watch": "jest --watch",
3030
"prepublish": "npm run build",
31-
"postinstall": "scripts/postinstall.sh"
31+
"postinstall": "node scripts/postinstall.js"
3232
},
3333
"devDependencies": {
3434
"eslint": "^4.11.0",

detox/scripts/build.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const childProcess = require('child_process');
2+
const fs = require('fs-extra');
3+
4+
// Just make the usage a little prettier
5+
function sh(cmdline, opts) {
6+
const args = cmdline.split(' ');
7+
const cmd = args.shift();
8+
return childProcess.execFileSync(cmd, args, opts);
9+
}
10+
11+
if (process.platform === 'darwin') {
12+
console.log("\nPackaging Detox iOS sources");
13+
14+
fs.removeSync('Detox-ios-src.tbz');
15+
// Prepare Earl Grey without building
16+
sh("ios/EarlGrey/Scripts/setup-earlgrey.sh");
17+
sh("find ./ios -name Build -type d -exec rm -rf {} ;");
18+
19+
sh("tar -cjf ../Detox-ios-src.tbz .", { cwd: "ios" });
20+
}
21+
22+
if (process.argv[2] === "android" || process.argv[3] === "android") {
23+
console.log("\nBuilding Detox aars");
24+
const aars = [
25+
"detox-minReactNative44-debug.aar",
26+
"detox-minReactNative46-debug.aar",
27+
"detox-minReactNative44-release.aar",
28+
"detox-minReactNative46-release.aar"
29+
];
30+
aars.forEach(aar => {
31+
fs.removeSync(aar);
32+
});
33+
34+
sh("./gradlew assembleDebug assembleRelease", {
35+
cwd: "android",
36+
stdio: "inherit",
37+
shell: true
38+
});
39+
40+
aars.forEach(aar => {
41+
fs.copySync(`android/detox/build/outputs/aar/${aar}`, aar);
42+
});
43+
}

detox/scripts/build.sh

Lines changed: 0 additions & 29 deletions
This file was deleted.

detox/scripts/postinstall.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
if (process.platform === "darwin") {
2+
require("child_process").execSync(`${__dirname}/build_framework.ios.sh`, {
3+
stdio: "inherit"
4+
});
5+
}

detox/scripts/postinstall.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)