/
options.js
68 lines (52 loc) · 1.7 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
/**
* @fileoverview Tests for options.
* @author Aniketh Saha
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const assert = require("assert"),
{ normalizeOptions } = require("../../lib/options");
//------------------------------------------------------------------------------
// 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 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);
});
});
});