-
-
Notifications
You must be signed in to change notification settings - Fork 189
/
options.js
75 lines (57 loc) · 1.96 KB
/
options.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
/**
* @fileoverview Tests for options.
* @author Aniketh Saha
*/
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
import assert from "assert";
import { normalizeOptions, getLatestEcmaVersion } from "../../lib/options.js";
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
describe("normalizeOptions", () => {
it("should set ecmaVersion to 5 if it wasn't specified", () => {
const option = {};
const output = normalizeOptions(option);
assert.strictEqual(output.ecmaVersion, 5);
});
it("should set ecmaVersion to latestEcmaVersion if ecmaVersion: latest is passed", () => {
const output = normalizeOptions({
ecmaVersion: "latest"
});
assert.strictEqual(output.ecmaVersion, getLatestEcmaVersion());
});
it("should throw error for sourceType module and ecmaVersion < 6", () => {
const option = {
sourceType: "module",
ecmaVersion: 5
};
assert.throws(() => {
normalizeOptions(option);
});
});
it("should normalize the ecmaVersion from year to version number", () => {
const option = {
ecmaVersion: 2018
};
const output = normalizeOptions(option);
assert.strictEqual(output.ecmaVersion, 9);
});
it("should throw error for unsupported ecmaVersion", () => {
const option = {
ecmaVersion: 2040
};
assert.throws(() => {
normalizeOptions(option);
});
});
it("should throw error for unsupported sourceType", () => {
const option = {
sourceType: "esm"
};
assert.throws(() => {
normalizeOptions(option);
});
});
});