Skip to content
This repository was archived by the owner on Oct 24, 2021. It is now read-only.

Commit 80bfeae

Browse files
committed
Add a "custom" test fixture to manually add coverage for specific cases.
This means we can't delete the entire fixtures directory for test setup, so instead check each repo individually, and get rid of the now useless "test:setup-once" script. Also fix a race condition between emptying the goldens directory and generating new goldens. Turns up now because the custom fixture is so fast to process.
1 parent c33fc1c commit 80bfeae

File tree

7 files changed

+59
-13
lines changed

7 files changed

+59
-13
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
/node_modules
22
/lib
3-
/src/test/fixtures
3+
4+
# All of the test fixtures are generated on install, except for "custom".
5+
/src/test/fixtures/*
6+
!/src/test/fixtures/custom

package-lock.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@
3939
"format": "find src -name '*.ts' -not -path 'src/test/fixtures/*' -not -path 'src/test/goldens/*' | xargs clang-format --style=file -i",
4040
"build": "npm run clean && tsc",
4141
"build:watch": "tsc --watch",
42-
"test": "npm run test:setup-once && npm run build && mocha",
42+
"test": "npm run test:setup && npm run build && mocha",
4343
"test:watch": "watchy -w src -- npm run test",
4444
"test:setup": "scripts/setup-fixtures.sh",
45-
"test:setup-once": "mkdir src/test/fixtures && npm run test:setup || true",
4645
"test:make-goldens": "npm run build && scripts/make-goldens.js"
4746
},
4847
"repository": {

scripts/make-goldens.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const {generateDeclarations} = require('../lib/gen-ts');
2828
const fixturesDir = path.join(__dirname, '..', 'src', 'test', 'fixtures');
2929
const goldensDir = path.join(__dirname, '..', 'src', 'test', 'goldens');
3030

31-
fsExtra.emptyDir(goldensDir);
31+
fsExtra.emptyDirSync(goldensDir);
3232

3333
for (const fixture of fs.readdirSync(fixturesDir)) {
3434
console.log('making goldens for ' + fixture);

scripts/setup-fixtures.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
set -e
1919

2020
cd src/test
21-
rm -rf fixtures
22-
mkdir fixtures
21+
mkdir -p fixtures
2322
cd fixtures
2423

2524
while read -r repo tag dir; do
25+
if [ -d $dir ]; then continue; fi # Already set up.
2626
git clone $repo $dir
2727
cd $dir
2828
git checkout $tag

src/test/fixtures/custom/my-class.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class MyClass {
2+
no_params() { }
3+
4+
one_param(p1) { }
5+
6+
two_params(p1, p2) { }
7+
8+
/**
9+
* @return {boolean}
10+
*/
11+
typed_return() { }
12+
13+
/**
14+
* @param {string} p1
15+
* @param {number} p2
16+
* @return {boolean}
17+
*/
18+
two_typed_params_and_typed_return(p1, p2) { }
19+
20+
/**
21+
* @param {...string} p1
22+
*/
23+
typed_rest_param(...p1) { }
24+
25+
/**
26+
* @param {string=} p1
27+
*/
28+
optional_param(p1) { }
29+
30+
/**
31+
* @param {string=} p2
32+
*/
33+
required_and_optional_param(p1, p2) { }
34+
}

src/test/goldens/custom/my-class.d.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
declare class MyClass {
2+
no_params(): any;
3+
one_param(p1: any): any;
4+
two_params(p1: any, p2: any): any;
5+
typed_return(): boolean;
6+
two_typed_params_and_typed_return(p1: string, p2: number): boolean;
7+
typed_rest_param(...p1: string[]): any;
8+
optional_param(p1?: string): any;
9+
required_and_optional_param(p1: any, p2?: string): any;
10+
}

0 commit comments

Comments
 (0)