Skip to content

Commit b7cfa59

Browse files
committed
load from tutorial directory when using param true
1 parent 3e3d29a commit b7cfa59

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

lib/reducers/run-tests/parse-loaders.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
var path = require('path');
33
var fs = require('fs');
44
var supportedFileTypes = ['js', 'jsx', 'ts', 'py'];
5-
var js = /^\/\/\s?load\(['"`](.+)['"`]\)$/m;
5+
var js = /^\/\/\s?load\(['"`](.+)['"`](\,\s?true)?\)/m;
66
var loaderMatch = {
77
js: js,
88
ts: js,
99
jsx: js,
10-
py: /^#\s?load\(['"`](.+)['"`]\)$/m
10+
py: /^#\s?load\(['"`](.+)['"`](,\s?true)?\)/m
1111
};
1212
function parseLoaders(data, fileType) {
1313
if (supportedFileTypes.indexOf(fileType) < 0) {
@@ -26,7 +26,13 @@ function parseLoaders(data, fileType) {
2626
console.log("\"" + fileToLoad + "\" already loaded.");
2727
continue;
2828
}
29-
var pathToFile = path.normalize(path.join(window.coderoad.dir, fileToLoad));
29+
var pathToFile = null;
30+
if (loader[2]) {
31+
pathToFile = path.normalize(path.join(window.coderoad.tutorialDir, fileToLoad));
32+
}
33+
else {
34+
pathToFile = path.normalize(path.join(window.coderoad.dir, fileToLoad));
35+
}
3036
lines[i] = fs.readFileSync(pathToFile, 'utf8');
3137
}
3238
}

src/reducers/run-tests/parse-loaders.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import * as path from 'path';
22
import * as fs from 'fs';
33

44
const supportedFileTypes = ['js', 'jsx', 'ts', 'py'];
5-
const js = /^\/\/\s?load\(['"`](.+)['"`]\)$/m; // // load('file'),
5+
const js = /^\/\/\s?load\(['"`](.+)['"`](\,\s?true)?\)/m; // // load('file'),
66
const loaderMatch = {
77
js,
88
ts: js,
99
jsx: js,
10-
py: /^#\s?load\(['"`](.+)['"`]\)$/m // # load('file')
10+
py: /^#\s?load\(['"`](.+)['"`](,\s?true)?\)/m // # load('file')
1111
};
1212

1313
export default function parseLoaders(data: string, fileType: string) {
@@ -36,7 +36,15 @@ export default function parseLoaders(data: string, fileType: string) {
3636
continue;
3737
}
3838

39-
let pathToFile: string = path.normalize(path.join(window.coderoad.dir, fileToLoad));
39+
let pathToFile: string = null;
40+
if (loader[2]) {
41+
// path to file from tutorial directory
42+
pathToFile = path.normalize(path.join(window.coderoad.tutorialDir, fileToLoad));
43+
} else {
44+
// path to file from working directory
45+
pathToFile = path.normalize(path.join(window.coderoad.dir, fileToLoad));
46+
}
47+
4048
lines[i] = fs.readFileSync(pathToFile, 'utf8');
4149
}
4250
}

0 commit comments

Comments
 (0)