/
ecma-features.js
82 lines (63 loc) · 2.56 KB
/
ecma-features.js
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* @fileoverview Tests for ECMA feature flags
* @author Nicholas C. Zakas
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const assert = require("assert"),
leche = require("leche"),
path = require("path"),
espree = require("../../espree"),
shelljs = require("shelljs"),
tester = require("./tester");
// var espree = require("esprima-fb");
//------------------------------------------------------------------------------
// Setup
//------------------------------------------------------------------------------
const FIXTURES_DIR = "./tests/fixtures/ecma-features";
const testFiles = shelljs.find(FIXTURES_DIR)
.filter(filename => filename.indexOf(".src.js") > -1)
.map(filename => filename.slice(FIXTURES_DIR.length - 1, filename.length - 7));
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
/**
* Returns whether a feature should throw in its tests when it is enabled.
* @param {string} feature The name of the feature.
* @returns {boolean} Whether it should throw in its tests when it is enabled.
*/
function shouldThrowInTestsWhenEnabled(feature) {
return (feature === "impliedStrict");
}
describe("ecmaFeatures", () => {
let config;
beforeEach(() => {
config = {
loc: true,
range: true,
tokens: true,
ecmaVersion: 6,
ecmaFeatures: {}
};
});
leche.withData(testFiles, filename => {
// Uncomment and fill in filename to focus on a single file
// var filename = "jsx/invalid-matching-placeholder-in-closing-tag";
const feature = path.dirname(filename),
isPermissive = !shouldThrowInTestsWhenEnabled(feature),
code = shelljs.cat(`${path.resolve(FIXTURES_DIR, filename)}.src.js`);
it(`should parse correctly when ${feature} is ${isPermissive}`, () => {
config.ecmaFeatures[feature] = isPermissive;
const expected = require(`${path.resolve(__dirname, "../../", FIXTURES_DIR, filename)}.result.js`);
tester.assertMatches(code, config, expected);
});
it(`should throw an error when ${feature} is ${!isPermissive}`, () => {
config.ecmaFeatures[feature] = !isPermissive;
assert.throws(() => {
espree.parse(code, config);
});
});
});
});