Skip to content
This repository was archived by the owner on Jan 14, 2019. It is now read-only.

Commit 96567db

Browse files
committed
test: add alignment test for espree & babel sourceType to unambiguous
1 parent 4ecdb8b commit 96567db

File tree

10 files changed

+795
-653
lines changed

10 files changed

+795
-653
lines changed

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
quote_type = single

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,20 @@
1919
"license": "BSD-2-Clause",
2020
"devDependencies": {
2121
"@babel/code-frame": "7.0.0",
22-
"@babel/parser": "7.1.6",
22+
"@babel/parser": "7.2.2",
2323
"@commitlint/cli": "^7.1.2",
2424
"@commitlint/config-conventional": "^7.1.2",
2525
"@commitlint/travis-cli": "^7.1.2",
2626
"@types/babel-code-frame": "^6.20.1",
27+
"@types/estree": "^0.0.39",
2728
"@types/jest": "^23.3.9",
2829
"@types/lodash.isplainobject": "^4.0.4",
2930
"@types/lodash.unescape": "^4.0.4",
3031
"@types/node": "^10.12.2",
3132
"@types/semver": "^5.5.0",
3233
"@types/shelljs": "^0.8.0",
3334
"cz-conventional-changelog": "2.1.0",
35+
"espree": "^5.0.0",
3436
"glob": "7.1.2",
3537
"husky": "0.14.3",
3638
"jest": "23.1.0",
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import glob from 'glob';
2+
import path from 'path';
3+
4+
export interface CreateFixturePatternConfig {
5+
ignoreBabel?: string[];
6+
ignoreEspree?: string[];
7+
fileType?: string;
8+
ignoreSourceType?: string[];
9+
}
10+
11+
export interface Fixture {
12+
filename: string;
13+
ignoreSourceType: boolean;
14+
}
15+
16+
export interface FixturePatternConfig {
17+
pattern: string;
18+
ignoreSourceType: boolean;
19+
}
20+
21+
export class FixturesTester {
22+
protected babelFixtures: FixturePatternConfig[] = [];
23+
protected espreeFixtures: FixturePatternConfig[] = [];
24+
25+
constructor() {}
26+
27+
public registerTest(
28+
fixturesSubPath: string,
29+
config: CreateFixturePatternConfig = {}
30+
) {
31+
const ignoreBabel = config.ignoreBabel || [];
32+
const ignoreEspree = config.ignoreEspree || [];
33+
const fileType = config.fileType || 'js';
34+
const ignoreSourceType = config.ignoreSourceType || [];
35+
36+
if (fileType === 'js' || fileType === 'jsx') {
37+
this.espreeFixtures.push({
38+
pattern: `${fixturesSubPath}/!(${ignoreEspree.join(
39+
'|'
40+
)}).src.${fileType}`,
41+
ignoreSourceType: false
42+
});
43+
}
44+
45+
/**
46+
* https://github.com/babel/babel/issues/9213
47+
*/
48+
if (ignoreSourceType.length) {
49+
ignoreBabel.push(...ignoreSourceType);
50+
for (const fixture of ignoreSourceType) {
51+
this.babelFixtures.push({
52+
// It needs to be the full path from within fixtures/ for the pattern
53+
pattern: `${fixturesSubPath}/${fixture}.src.${config.fileType}`,
54+
ignoreSourceType: true
55+
});
56+
}
57+
}
58+
59+
this.babelFixtures.push({
60+
pattern: `${fixturesSubPath}/!(${ignoreBabel.join('|')}).src.${fileType}`,
61+
ignoreSourceType: false
62+
});
63+
}
64+
65+
protected processFixtures(fixtures: FixturePatternConfig[]): Fixture[] {
66+
const fixturesDirPath = path.join(__dirname, '../fixtures');
67+
68+
return fixtures
69+
.map(fixtures => {
70+
return glob
71+
.sync(`${fixturesDirPath}/${fixtures.pattern}`, {})
72+
.map(filename => {
73+
return {
74+
filename,
75+
ignoreSourceType: fixtures.ignoreSourceType
76+
};
77+
});
78+
})
79+
.reduce((acc, x) => acc.concat(x), []);
80+
}
81+
82+
public getForBabel(): Fixture[] {
83+
return this.processFixtures(this.babelFixtures);
84+
}
85+
86+
public getForEspree(): Fixture[] {
87+
return this.processFixtures(this.espreeFixtures);
88+
}
89+
}

0 commit comments

Comments
 (0)