Skip to content

Commit 0e13400

Browse files
authored
[chore] Prettify test files (#6357)
* Update prettierignore to include test input.js files * Format test files
1 parent 61c5592 commit 0e13400

File tree

18 files changed

+134
-120
lines changed

18 files changed

+134
-120
lines changed

.prettierignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
jscomp/
1+
jscomp/*
2+
!jscomp/build_tests
3+
jscomp/build_tests/*/**
4+
!jscomp/build_tests/*/input.js
25
lib/
36
vendor/
47
ninja/

jscomp/build_tests/case/input.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1+
var p = require("child_process");
2+
var assert = require("assert");
3+
var rescript_exe = require("../../../scripts/bin_path").rescript_exe;
4+
var o = p.spawnSync(rescript_exe, { encoding: "utf8", cwd: __dirname });
15

2-
3-
var p = require('child_process')
4-
var assert = require('assert')
5-
var rescript_exe = require("../../../scripts/bin_path").rescript_exe
6-
var o = p.spawnSync(rescript_exe,{encoding: 'utf8',cwd : __dirname})
7-
8-
9-
assert.ok(o.stderr.match(/different cases/).length > 0 )
6+
assert.ok(o.stderr.match(/different cases/).length > 0);

jscomp/build_tests/cmd/input.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function evalCode(code) {
3434
{
3535
encoding: "utf8",
3636
shell: true,
37-
cwd: __dirname
37+
cwd: __dirname,
3838
}
3939
);
4040

jscomp/build_tests/cycle/input.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
//@ts-check
22
const cp = require("child_process");
33
const assert = require("assert");
4-
const fs = require('fs')
5-
const path = require('path')
4+
const fs = require("fs");
5+
const path = require("path");
66
var rescript_exe = require("../../../scripts/bin_path").rescript_exe;
77

88
var output = cp.spawnSync(rescript_exe, { encoding: "utf8", shell: true });
99

1010
assert(/dependency cycle/.test(output.stdout));
1111

12-
var compilerLogFile = path.join(__dirname, 'lib', 'bs', '.compiler.log');
13-
var compilerLog = fs.readFileSync(compilerLogFile, 'utf8');
12+
var compilerLogFile = path.join(__dirname, "lib", "bs", ".compiler.log");
13+
var compilerLog = fs.readFileSync(compilerLogFile, "utf8");
1414
assert(/dependency cycle/.test(compilerLog));

jscomp/build_tests/cycle1/input.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
//@ts-check
22
const cp = require("child_process");
33
const assert = require("assert");
4-
const fs = require('fs')
5-
const path = require('path')
6-
var rescript_exe = require("../../../scripts/bin_path").rescript_exe
4+
const fs = require("fs");
5+
const path = require("path");
6+
var rescript_exe = require("../../../scripts/bin_path").rescript_exe;
77

8-
cp.execSync(`${rescript_exe} clean`, { cwd: __dirname, });
8+
cp.execSync(`${rescript_exe} clean`, { cwd: __dirname });
99

1010
var output = cp.spawnSync(rescript_exe, { encoding: "utf8", shell: true });
1111

1212
assert(/is dangling/.test(output.stdout));
1313

14-
var compilerLogFile = path.join(__dirname, 'lib', 'bs', '.compiler.log');
15-
var compilerLog = fs.readFileSync(compilerLogFile, 'utf8');
14+
var compilerLogFile = path.join(__dirname, "lib", "bs", ".compiler.log");
15+
var compilerLog = fs.readFileSync(compilerLogFile, "utf8");
1616
assert(/is dangling/.test(compilerLog));

jscomp/build_tests/devonly/input.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ts-check
22
var cp = require("child_process");
3-
var rescript_exe = require("../../../scripts/bin_path").rescript_exe
3+
var rescript_exe = require("../../../scripts/bin_path").rescript_exe;
44

55
cp.execSync(rescript_exe, { cwd: __dirname, encoding: "utf8" });
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
const fs = require('fs')
2-
const path = require('path')
3-
const child_process = require('child_process')
4-
const rescript_exe = require("../../../scripts/bin_path").rescript_exe
1+
const fs = require("fs");
2+
const path = require("path");
3+
const child_process = require("child_process");
4+
const rescript_exe = require("../../../scripts/bin_path").rescript_exe;
55

6-
const expectedFilePath = path.join(__dirname, 'out.expected')
6+
const expectedFilePath = path.join(__dirname, "out.expected");
77

8-
const updateTests = process.argv[2] === 'update'
8+
const updateTests = process.argv[2] === "update";
99

10-
function postProcessErrorOutput (output) {
11-
output = output.trimRight()
12-
output = output.replace(new RegExp(__dirname, 'gi'), '.')
13-
return output
10+
function postProcessErrorOutput(output) {
11+
output = output.trimRight();
12+
output = output.replace(new RegExp(__dirname, "gi"), ".");
13+
return output;
1414
}
15-
child_process.execSync(`${rescript_exe} clean`,{cwd:__dirname})
16-
child_process.exec(rescript_exe, {cwd: __dirname}, (err, stdout, stderr) => {
17-
const actualErrorOutput = postProcessErrorOutput(stderr.toString())
15+
child_process.execSync(`${rescript_exe} clean`, { cwd: __dirname });
16+
child_process.exec(rescript_exe, { cwd: __dirname }, (err, stdout, stderr) => {
17+
const actualErrorOutput = postProcessErrorOutput(stderr.toString());
1818
if (updateTests) {
19-
fs.writeFileSync(expectedFilePath, actualErrorOutput)
19+
fs.writeFileSync(expectedFilePath, actualErrorOutput);
2020
} else {
21-
const expectedErrorOutput = postProcessErrorOutput(fs.readFileSync(expectedFilePath, {encoding: 'utf-8'}))
21+
const expectedErrorOutput = postProcessErrorOutput(
22+
fs.readFileSync(expectedFilePath, { encoding: "utf-8" })
23+
);
2224
if (expectedErrorOutput !== actualErrorOutput) {
23-
console.error(`The old and new error output aren't the same`)
24-
console.error('\n=== Old:')
25-
console.error(expectedErrorOutput)
26-
console.error('\n=== New:')
27-
console.error(actualErrorOutput)
28-
process.exit(1)
25+
console.error(`The old and new error output aren't the same`);
26+
console.error("\n=== Old:");
27+
console.error(expectedErrorOutput);
28+
console.error("\n=== New:");
29+
console.error(actualErrorOutput);
30+
process.exit(1);
2931
}
3032
}
31-
})
32-
33-
33+
});

jscomp/build_tests/in_source/input.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
var child_process = require('child_process')
1+
var child_process = require("child_process");
22

3-
var assert = require('assert')
4-
5-
var rescript_exe = require("../../../scripts/bin_path").rescript_exe
3+
var assert = require("assert");
64

5+
var rescript_exe = require("../../../scripts/bin_path").rescript_exe;
76

87
assert.throws(
9-
() => {
10-
var output = child_process.execSync(`${rescript_exe} build -regen`,
11-
{ cwd: __dirname, encoding: 'utf8' }
12-
)
13-
}
14-
,
15-
function (err){
16-
if (err.message.match(/detected two module formats/)){
17-
return true
18-
}
19-
return false
8+
() => {
9+
var output = child_process.execSync(`${rescript_exe} build -regen`, {
10+
cwd: __dirname,
11+
encoding: "utf8",
12+
});
13+
},
14+
function (err) {
15+
if (err.message.match(/detected two module formats/)) {
16+
return true;
2017
}
21-
22-
)
23-
18+
return false;
19+
}
20+
);
2421

2522
// assert.throws(()=>{
2623
// throw new Error('Wrong value')

jscomp/build_tests/install/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ p.spawnSync(rescript_exe, [`clean`], {
88
encoding: "utf8",
99
cwd: __dirname,
1010
});
11-
p.spawnSync(rescript_exe, [`build`,`-install`], {
11+
p.spawnSync(rescript_exe, [`build`, `-install`], {
1212
encoding: "utf8",
1313
cwd: __dirname,
1414
});
@@ -20,7 +20,7 @@ p.spawnSync(rescript_exe, {
2020
encoding: "utf8",
2121
cwd: __dirname,
2222
});
23-
p.spawnSync(rescript_exe ,[`build`,`-install`], {
23+
p.spawnSync(rescript_exe, [`build`, `-install`], {
2424
encoding: "utf8",
2525
cwd: __dirname,
2626
});

jscomp/build_tests/rerror/input.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var u = o.stdout.match(/=>/g);
1616

1717
var lines = o.stdout
1818
.split("\n")
19-
.map((x) => x.trim())
19+
.map(x => x.trim())
2020
.filter(Boolean);
2121
// console.log(`lines: \n${lines}`)
2222
// console.log(lines[4])
Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,64 @@
1-
const fs = require('fs')
2-
const path = require('path')
3-
const child_process = require('child_process')
4-
1+
const fs = require("fs");
2+
const path = require("path");
3+
const child_process = require("child_process");
54

65
var bsc = require("../../../scripts/bin_path").bsc_exe;
76

8-
const expectedDir = path.join(__dirname, 'expected')
7+
const expectedDir = path.join(__dirname, "expected");
98

109
const fixtures = fs
11-
.readdirSync(path.join(__dirname, 'fixtures'))
12-
.filter(fileName => path.extname(fileName) === '.res')
10+
.readdirSync(path.join(__dirname, "fixtures"))
11+
.filter(fileName => path.extname(fileName) === ".res");
1312

1413
// const runtime = path.join(__dirname, '..', '..', 'runtime')
15-
const prefix = `${bsc} -w +A`
14+
const prefix = `${bsc} -w +A`;
1615

17-
const updateTests = process.argv[2] === 'update'
16+
const updateTests = process.argv[2] === "update";
1817

1918
function postProcessErrorOutput(output) {
20-
output = output.trimRight()
21-
output = output.replace(/\/[^ ]+?jscomp\/build_tests\/super_errors\//g, '/.../')
22-
return output
19+
output = output.trimRight();
20+
output = output.replace(
21+
/\/[^ ]+?jscomp\/build_tests\/super_errors\//g,
22+
"/.../"
23+
);
24+
return output;
2325
}
2426

25-
let doneTasksCount = 0
26-
let atLeastOneTaskFailed = false
27+
let doneTasksCount = 0;
28+
let atLeastOneTaskFailed = false;
2729

2830
fixtures.forEach(fileName => {
29-
const fullFilePath = path.join(__dirname, 'fixtures', fileName)
30-
const command = `${prefix} -color always ${fullFilePath}`
31-
console.log(`running ${command}`)
31+
const fullFilePath = path.join(__dirname, "fixtures", fileName);
32+
const command = `${prefix} -color always ${fullFilePath}`;
33+
console.log(`running ${command}`);
3234
child_process.exec(command, (err, stdout, stderr) => {
33-
doneTasksCount++
35+
doneTasksCount++;
3436
// careful of:
3537
// - warning test that actually succeeded in compiling (warning's still in stderr, so the code path is shared here)
3638
// - accidentally succeeding tests (not likely in this context),
3739
// actual, correctly erroring test case
38-
const actualErrorOutput = postProcessErrorOutput(stderr.toString())
39-
const expectedFilePath = path.join(expectedDir, fileName + '.expected')
40+
const actualErrorOutput = postProcessErrorOutput(stderr.toString());
41+
const expectedFilePath = path.join(expectedDir, fileName + ".expected");
4042
if (updateTests) {
41-
fs.writeFileSync(expectedFilePath, actualErrorOutput)
43+
fs.writeFileSync(expectedFilePath, actualErrorOutput);
4244
} else {
43-
const expectedErrorOutput = postProcessErrorOutput(fs.readFileSync(expectedFilePath, {encoding: 'utf-8'}))
45+
const expectedErrorOutput = postProcessErrorOutput(
46+
fs.readFileSync(expectedFilePath, { encoding: "utf-8" })
47+
);
4448
if (expectedErrorOutput !== actualErrorOutput) {
45-
console.error(`The old and new error output for the test ${fullFilePath} aren't the same`)
46-
console.error('\n=== Old:')
47-
console.error(expectedErrorOutput)
48-
console.error('\n=== New:')
49-
console.error(actualErrorOutput)
50-
atLeastOneTaskFailed = true
49+
console.error(
50+
`The old and new error output for the test ${fullFilePath} aren't the same`
51+
);
52+
console.error("\n=== Old:");
53+
console.error(expectedErrorOutput);
54+
console.error("\n=== New:");
55+
console.error(actualErrorOutput);
56+
atLeastOneTaskFailed = true;
5157
}
5258

5359
if (doneTasksCount === fixtures.length && atLeastOneTaskFailed) {
54-
process.exit(1)
60+
process.exit(1);
5561
}
5662
}
57-
})
58-
})
63+
});
64+
});
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
//@ts-check
22
var child_process = require("child_process");
33
var assert = require("assert");
4-
var fs = require("fs")
4+
var fs = require("fs");
55
var rescript_exe = require("../../../scripts/bin_path").rescript_exe;
66

7-
console.log(child_process.execSync(rescript_exe, { encoding: "utf8", cwd: "./a" }));
7+
console.log(
8+
child_process.execSync(rescript_exe, { encoding: "utf8", cwd: "./a" })
9+
);
810

9-
assert(fs.existsSync("./node_modules/c/lib/js/tests/test.mjs"), "dev files of module 'c' were not built by 'a' even though 'c' is a transitive pinned dependency of 'a' through 'b'")
11+
assert(
12+
fs.existsSync("./node_modules/c/lib/js/tests/test.mjs"),
13+
"dev files of module 'c' were not built by 'a' even though 'c' is a transitive pinned dependency of 'a' through 'b'"
14+
);
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
//@ts-check
22
var child_process = require("child_process");
33
var assert = require("assert");
4-
var fs = require("fs")
4+
var fs = require("fs");
55
var rescript_exe = require("../../../scripts/bin_path").rescript_exe;
66

7-
console.log(child_process.execSync(rescript_exe, { encoding: "utf8", cwd: "./a" }));
7+
console.log(
8+
child_process.execSync(rescript_exe, { encoding: "utf8", cwd: "./a" })
9+
);
810

9-
assert(!fs.existsSync("./node_modules/c/lib/js/tests/test.mjs"), "dev files of module 'c' were built by 'a' even though 'c' is not a pinned dependency of 'a'")
11+
assert(
12+
!fs.existsSync("./node_modules/c/lib/js/tests/test.mjs"),
13+
"dev files of module 'c' were built by 'a' even though 'c' is not a pinned dependency of 'a'"
14+
);
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//@ts-check
22
const cp = require("child_process");
33
const assert = require("assert");
4-
const fs = require('fs')
5-
const path = require('path')
6-
var rescript_exe = require("../../../scripts/bin_path").rescript_exe
4+
const fs = require("fs");
5+
const path = require("path");
6+
var rescript_exe = require("../../../scripts/bin_path").rescript_exe;
77

8-
cp.execSync(`${rescript_exe} clean`, { cwd: __dirname, });
9-
cp.execSync(`${rescript_exe}`, { cwd: __dirname, });
8+
cp.execSync(`${rescript_exe} clean`, { cwd: __dirname });
9+
cp.execSync(`${rescript_exe}`, { cwd: __dirname });

jscomp/build_tests/unicode/input.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ var content =
1111

1212
var assert = require("assert");
1313

14-
assert(JSON.parse(content).dirs.some((x) => x.includes("📕annotation")));
14+
assert(JSON.parse(content).dirs.some(x => x.includes("📕annotation")));

jscomp/build_tests/x-y/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var p = require('child_process')
1+
var p = require("child_process");
22
var rescript_exe = require("../../../scripts/bin_path").rescript_exe;
33

4-
p.execSync(rescript_exe)
4+
p.execSync(rescript_exe);

jscomp/build_tests/xpkg/input.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
var p = require('child_process')
2-
var assert = require('assert')
3-
var fs = require('fs')
1+
var p = require("child_process");
2+
var assert = require("assert");
3+
var fs = require("fs");
44
var rescript_exe = require("../../../scripts/bin_path").rescript_exe;
55
try {
6-
var output = p.spawnSync(`${rescript_exe} build -regen`, { shell: true, encoding: 'utf8' })
6+
var output = p.spawnSync(`${rescript_exe} build -regen`, {
7+
shell: true,
8+
encoding: "utf8",
9+
});
710

8-
assert.ok(output.stderr.match(/reserved package name/))
9-
}
10-
finally {
11-
11+
assert.ok(output.stderr.match(/reserved package name/));
12+
} finally {
1213
}

jscomp/build_tests/zerocycle/input.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ var p = require("child_process");
22
var assert = require("assert");
33
var rescript_exe = require("../../../scripts/bin_path").rescript_exe;
44
var out = p.spawnSync(rescript_exe, { encoding: "utf8", cwd: __dirname });
5-
assert(out.status == 0)
5+
assert(out.status == 0);

0 commit comments

Comments
 (0)