Skip to content

Commit

Permalink
Chore: Add tests for ecmaVersion default value (#460)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic committed Nov 25, 2020
1 parent 4c70052 commit 0e09d9a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/lib/options.js
Expand Up @@ -17,6 +17,14 @@ const assert = require("assert"),
//------------------------------------------------------------------------------

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",
Expand Down
15 changes: 15 additions & 0 deletions tests/lib/parse.js
Expand Up @@ -19,6 +19,21 @@ const assert = require("assert"),

describe("parse()", () => {

describe("ecmaVersion", () => {

it("should be 5 if not specified", () => {

// `ecmaVersion: 3` would throw on getters/setters
espree.parse("var foo = { get bar() {} }");

// needs `ecmaVersion: 6` or higher
assert.throws(() => {
espree.parse("let foo");
});
});

});

describe("modules", () => {

it("should have correct column number when strict mode error occurs", () => {
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/tokenize.js
Expand Up @@ -19,6 +19,16 @@ const assert = require("assert"),

describe("tokenize()", () => {

it("should have `ecmaVersion: 5` as default", () => {

// FIXME: is there a way to test that it isn't `ecmaVersion: 3`?

// needs `ecmaVersion: 6` or higher
assert.throws(() => {
espree.tokenize("`template`");
});
});

it("should produce tokens when using let", () => {
const tokens = espree.tokenize("let foo = bar;", {
ecmaVersion: 6,
Expand Down

0 comments on commit 0e09d9a

Please sign in to comment.