forked from microsoft/pxt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorialrunner.ts
More file actions
61 lines (49 loc) · 1.82 KB
/
tutorialrunner.ts
File metadata and controls
61 lines (49 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/// <reference path="../../built/pxtcompiler.d.ts"/>
import * as fs from 'fs';
import * as path from 'path';
import "mocha";
import * as chai from "chai";
import * as util from "../common/testUtils";
const casesDir = path.join(process.cwd(), "tests", "tutorial-test", "cases");
const baselineDir = path.join(process.cwd(), "tests", "tutorial-test", "baselines");
// Just needs to exist
pxt.setAppTarget(util.testAppTarget);
describe("tutorial test cases", () => {
const filenames: string[] = [];
for (const file of fs.readdirSync(casesDir)) {
if (file[0] == ".") {
continue;
}
const filename = path.join(casesDir, file)
if (file.substr(-3) === ".md") {
filenames.push(filename)
}
};
filenames.forEach(filename => {
it("should correctly parse " + path.basename(filename), () => {
tutorialTest(filename)
});
});
});
function tutorialTest(filename: string) {
const input = fs.readFileSync(filename, "utf8");
const basename = path.basename(filename).slice(0, -3) + ".json";
const baselinePath = path.join(baselineDir, basename);
let info = pxt.tutorial.parseTutorial(input);
let baseline;
try {
baseline = JSON.parse(fs.readFileSync(baselinePath, "utf8"));
}
catch (e) {
// If there isn't a baseline, generate one.
let newBaseline = info;
fs.writeFileSync(baselinePath, JSON.stringify(newBaseline, null, 4));
}
baseline = baseline || info;
let err = pxt.Util.deq(baseline, info);
if (err) {
fs.writeFileSync(baselinePath + ".original", JSON.stringify(baseline, null, 4));
fs.writeFileSync(baselinePath, JSON.stringify(info, null, 4));
}
chai.assert(err === null, `Parsed tutorial did not match baseline. See ${basename} diff for details.`);
}