Skip to content

Commit 0fe28fe

Browse files
committed
fix filepath bug on windows
1 parent 14c48d9 commit 0fe28fe

File tree

11 files changed

+34
-22
lines changed

11 files changed

+34
-22
lines changed

lib/runner/paths/node.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var path_1 = require('path');
33
function getNode() {
44
if (process.platform === 'darwin' && process.resourcesPath) {
5-
return path_1.resolve(process.resourcesPath, '..', 'Frameworks', 'Atom Helper.app', 'Contents', 'MacOS', 'Atom Helper');
5+
return path_1.join(process.resourcesPath, '..', 'Frameworks', 'Atom Helper.app', 'Contents', 'MacOS', 'Atom Helper');
66
}
77
else if (process.platform.match(/win/)) {
88
return 'node';

lib/testPath.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
"use strict";
22
var path_1 = require('path');
3+
var isWindows = window.navigator.appVersion.indexOf('Win') > -1 || false;
34
function tmpTestName(testFile) {
4-
return path_1.resolve(__dirname, '..', '.tmp', testFile + '.js');
5+
var testPath = path_1.join(__dirname, '..', '.tmp', testFile + '.js');
6+
if (isWindows) {
7+
testPath = testPath.split('/').join('\\');
8+
}
9+
return testPath;
510
}
611
Object.defineProperty(exports, "__esModule", { value: true });
712
exports.default = tmpTestName;

lib/writeTests/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"use strict";
2-
var fs = require('fs');
2+
var fs_1 = require('fs');
33
var path_1 = require('path');
44
var js_coderoad_1 = require('js-coderoad');
55
var tmpPath = path_1.join(__dirname, '..', '..', '.tmp');
@@ -11,11 +11,11 @@ function writeTest(_a) {
1111
Object.defineProperty(exports, "__esModule", { value: true });
1212
exports.default = writeTest;
1313
function writeTestFile(testPath, output) {
14-
if (!fs.existsSync(tmpPath)) {
15-
fs.mkdirSync(tmpPath);
14+
if (!fs_1.existsSync(tmpPath)) {
15+
fs_1.mkdirSync(tmpPath);
1616
}
1717
return new Promise(function (resolve, reject) {
18-
fs.writeFile(testPath, output, function (err) {
18+
fs_1.writeFile(testPath, output, function (err) {
1919
if (err) {
2020
reject(err);
2121
}

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mocha-coderoad",
3-
"version": "0.10.1",
3+
"version": "0.10.2",
44
"description": "mocha test runner & reporter for atom-coderoad",
55
"keywords": [
66
"coderoad",
@@ -26,7 +26,7 @@
2626
"test": "echo \"Error: no test specified\" && exit 1"
2727
},
2828
"dependencies": {
29-
"js-coderoad": "^0.1.2",
29+
"js-coderoad": "^0.1.3",
3030
"mocha": "^3.0.2",
3131
"node-file-exists": "1.1.0"
3232
},

src/reporter/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {signal} from '../constants';
1+
import { signal } from '../constants';
22

33
exports = module.exports = reporter;
44
function reporter(runner) {

src/runner/paths/mocha.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fileExists from 'node-file-exists';
2-
import {join} from 'path';
2+
import { join } from 'path';
33

44
export default function getMocha(): string {
55
// mocha, location may differ based on NPM version

src/runner/paths/node.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import {resolve} from 'path';
1+
import { join } from 'path';
22

33
export default function getNode(): string {
44
if (process.platform === 'darwin' && process.resourcesPath) {
5-
return resolve(process.resourcesPath, '..', 'Frameworks', 'Atom Helper.app', 'Contents', 'MacOS', 'Atom Helper');
5+
return join(process.resourcesPath, '..', 'Frameworks', 'Atom Helper.app', 'Contents', 'MacOS', 'Atom Helper');
66
} else if (process.platform.match(/win/)) {
77
return 'node';
88
}

src/runner/runner-process.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {join} from 'path';
2-
import {spawn} from 'child_process';
1+
import { join } from 'path';
2+
import { spawn } from 'child_process';
33

44
import getMocha from './paths/mocha';
55
import getNode from './paths/node';

src/runner/start-runner.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {parseLog} from 'process-console-log';
2-
import {signal} from '../constants';
1+
import { parseLog } from 'process-console-log';
2+
import { signal } from '../constants';
33

44
// take code after the signal to avoid confusing console.log statements
55
// with test output

src/testPath.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
import { resolve } from 'path';
1+
import { join } from 'path';
2+
3+
const isWindows = window.navigator.appVersion.indexOf('Win') > -1 || false;
24

35
export default function tmpTestName(testFile: string): string {
4-
return resolve(__dirname, '..', '.tmp', testFile + '.js');
6+
let testPath = join(__dirname, '..', '.tmp', testFile + '.js');
7+
// fix bug on Windows for test paths
8+
if (isWindows) {
9+
testPath = testPath.split('/').join('\\');
10+
}
11+
return testPath;
512
}

src/writeTests/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as fs from 'fs';
1+
import { existsSync, mkdirSync, writeFile } from 'fs';
22
import { join } from 'path';
33
import jsCodeRoad from 'js-coderoad';
44

@@ -14,12 +14,12 @@ export default function writeTest({ dir, tests, testPath }) {
1414

1515
function writeTestFile(testPath: string, output: string) {
1616
// create .tmp directory if doesn't exist
17-
if (!fs.existsSync(tmpPath)) {
18-
fs.mkdirSync(tmpPath);
17+
if (!existsSync(tmpPath)) {
18+
mkdirSync(tmpPath);
1919
}
2020
return new Promise((resolve, reject) => {
2121
// write test file
22-
fs.writeFile(testPath, output, (err) => {
22+
writeFile(testPath, output, (err) => {
2323
if (err) { reject(err); }
2424
resolve();
2525
});

0 commit comments

Comments
 (0)