-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
commonjs.cjs
94 lines (79 loc) · 2.72 KB
/
commonjs.cjs
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
83
84
85
86
87
88
89
90
91
92
93
94
/**
* @fileoverview Tests for checking that the commonjs entry points are still accessible
* @author Mike Reinstein
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const assert = require("assert");
const eslintrc = require("../../dist/eslintrc.cjs");
const universal = require("../../dist/eslintrc-universal.cjs");
const path = require("path");
const sh = require("shelljs");
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
describe("eslintrc CommonJS", () => {
it("is an object", () => {
assert.strictEqual(typeof eslintrc, "object");
});
it("has exports", () => {
assert.strictEqual(typeof eslintrc.FlatCompat, "function");
assert.strictEqual(typeof eslintrc.Legacy, "object");
[
"ConfigArray",
"createConfigArrayFactoryContext",
"CascadingConfigArrayFactory",
"ConfigArrayFactory",
"ConfigDependency",
"ExtractedConfig",
"IgnorePattern",
"OverrideTester",
"getUsedExtractedConfigs",
"ConfigValidator"
].forEach(prop => {
assert.strictEqual(typeof eslintrc.Legacy[prop], "function");
});
// shared
[
"environments",
"ConfigOps",
"ModuleResolver",
"naming"
].forEach(prop => {
assert.strictEqual(typeof eslintrc.Legacy[prop], "object");
});
});
});
describe("eslintrc CommonJS Universal", () => {
it("is an object", () => {
assert.strictEqual(typeof universal, "object");
});
it("has exports", () => {
assert.strictEqual(typeof universal.Legacy, "object");
assert.strictEqual(typeof universal.Legacy.ConfigValidator, "function");
// shared
[
"environments",
"ConfigOps",
"naming"
].forEach(prop => {
assert.strictEqual(typeof universal.Legacy[prop], "object");
});
});
});
// https://github.com/eslint/eslint/issues/15766
describe("eslintrc CommonJS loading", () => {
const testDir = path.resolve(__dirname, "../../tmp/my%2Fproject");
before(() => {
sh.mkdir("-p", testDir);
sh.cp("", "./dist/eslintrc.cjs", testDir);
});
after(() => {
sh.rm("-r", testDir);
});
it("eslintrc.cjs module successfully loads when it is in a path that contains URL-encoded characters", () => {
require(path.resolve(testDir, "eslintrc.cjs"));
});
});