Skip to content

Commit a9ba05e

Browse files
authored
Merge pull request #225 from yowainwright/init-add-more-tests
Init add more tests
2 parents b634521 + 2e16103 commit a9ba05e

File tree

3 files changed

+136
-4
lines changed

3 files changed

+136
-4
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Ensuring that JavaScript files can pass ES Check is important in a [modular and
2222

2323
## Version 8 🎉
2424

25-
**ES Check** version 8 is a major release update that can enforce actual ES version specific features checks; no longer just that a files are syntatically correct to the es version. To enable this feature, just pass the `--checkFeatures` flag. This feature will become default in version 9. Besides this, there are minor feature updates based on user feedback—glob matching updates and some optional fixes.
25+
**ES Check** version 8 is a major release update that can enforce actual ES version specific features checks; no longer just that a files are syntatically correct to the es version. To enable this feature, just pass the `--checkFeatures` flag. This feature will become default in version 9. Besides this, there are minor feature updates based on user feedback—glob matching updates and some optional fixes. This should not break any existing scripts. Please report any issues!
2626

2727
```sh
2828
es-check es6 './dist/**/*.js' --checkFeatures
@@ -39,7 +39,6 @@ es-check es6 './dist/**/*.js' --checkFeatures
3939
<a href="#debugging">Debugging</a>&nbsp;&nbsp;
4040
<a href="#contributing">Contributing</a>&nbsp;&nbsp;
4141
<a href="/issues">Issues</a>
42-
<a href="#roadmap">Roadmap</a>
4342
</p>
4443

4544
---
@@ -73,6 +72,10 @@ es-check es5 './vendor/js/*.js' './dist/**/*.js'
7372

7473
In modern JavaScript builds, files are bundled up so they can be served in an optimized manner in the browsers. It is assumed by developers that future JavaScript—like ES8 will be transpiled (changed from future JavaScript to current JavaScript) appropriately by a tool like Babel. Sometimes there is an issue where files are not transpiled. There was no efficient way to test for files that weren't transpiled—until now. That's what ES Check does.
7574

75+
## What features does ES Check check for?
76+
77+
ES Check checks syntax out of the box—to protect against breaking errors going to production. Additionally, by adding the `--checkFeatures` flag, ES Check will check for actual ES version specific features. This ensures that your code is syntactically correct and only using features that are available in the specified ES version. Look here to view/add [features](./constants.js) that ES Check checks for with the `--checkFeatures` flag!
78+
7679
---
7780

7881
## Walk through
@@ -99,7 +102,7 @@ Fail
99102

100103
# USAGE
101104

102-
index.js es-check <ecmaVersion> [files...]
105+
es-check <ecmaVersion> [files...]
103106

104107
```
105108

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"release": "release-it",
2626
"report:coverage": "nyc report --reporter=lcov > coverage.lcov && codecov",
2727
"setup": "pnpm install --reporter=silent",
28-
"test": "nyc mocha test.js --timeout 10s --coverage",
28+
"test": "nyc mocha test.js utils.test.js --timeout 10s",
2929
"update": "codependence --update"
3030
},
3131
"repository": {

utils.test.js

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// test/checkFunctions.spec.js
2+
3+
const assert = require('assert');
4+
const {
5+
checkVarKindMatch,
6+
checkCalleeMatch,
7+
checkOperatorMatch,
8+
checkDefault,
9+
checkMap,
10+
} = require('./utils');
11+
12+
describe('Check Functions', function () {
13+
describe('checkVarKindMatch', function () {
14+
it('should return false if astInfo.kind is not provided', function () {
15+
const node = { kind: 'const' };
16+
const astInfo = {}; // no "kind"
17+
assert.strictEqual(checkVarKindMatch(node, astInfo), false);
18+
});
19+
20+
it('should return true if node.kind equals astInfo.kind', function () {
21+
const node = { kind: 'const' };
22+
const astInfo = { kind: 'const' };
23+
assert.strictEqual(checkVarKindMatch(node, astInfo), true);
24+
});
25+
26+
it('should return false if node.kind does not match astInfo.kind', function () {
27+
const node = { kind: 'let' };
28+
const astInfo = { kind: 'const' };
29+
assert.strictEqual(checkVarKindMatch(node, astInfo), false);
30+
});
31+
});
32+
33+
describe('checkCalleeMatch', function () {
34+
it('should return false if astInfo.callee is not provided', function () {
35+
const node = {
36+
callee: { type: 'Identifier', name: 'Promise' },
37+
};
38+
const astInfo = {}; // no "callee"
39+
assert.strictEqual(checkCalleeMatch(node, astInfo), false);
40+
});
41+
42+
it('should return false if node.callee is missing', function () {
43+
const node = {};
44+
const astInfo = { callee: 'Promise' };
45+
assert.strictEqual(checkCalleeMatch(node, astInfo), false);
46+
});
47+
48+
it('should return false if node.callee.type !== "Identifier"', function () {
49+
const node = {
50+
callee: { type: 'MemberExpression', name: 'Promise' },
51+
};
52+
const astInfo = { callee: 'Promise' };
53+
assert.strictEqual(checkCalleeMatch(node, astInfo), false);
54+
});
55+
56+
it('should return false if the callee name does not match astInfo.callee', function () {
57+
const node = {
58+
callee: { type: 'Identifier', name: 'WeakRef' },
59+
};
60+
const astInfo = { callee: 'Promise' };
61+
assert.strictEqual(checkCalleeMatch(node, astInfo), false);
62+
});
63+
64+
it('should return true if callee name matches astInfo.callee', function () {
65+
const node = {
66+
callee: { type: 'Identifier', name: 'Promise' },
67+
};
68+
const astInfo = { callee: 'Promise' };
69+
assert.strictEqual(checkCalleeMatch(node, astInfo), true);
70+
});
71+
});
72+
73+
describe('checkOperatorMatch', function () {
74+
it('should return false if astInfo.operator is not provided', function () {
75+
const node = { operator: '??' };
76+
const astInfo = {}; // no "operator"
77+
assert.strictEqual(checkOperatorMatch(node, astInfo), false);
78+
});
79+
80+
it('should return false if node.operator does not match astInfo.operator', function () {
81+
const node = { operator: '**' };
82+
const astInfo = { operator: '??' };
83+
assert.strictEqual(checkOperatorMatch(node, astInfo), false);
84+
});
85+
86+
it('should return true if node.operator matches astInfo.operator', function () {
87+
const node = { operator: '??' };
88+
const astInfo = { operator: '??' };
89+
assert.strictEqual(checkOperatorMatch(node, astInfo), true);
90+
});
91+
});
92+
93+
describe('checkDefault', function () {
94+
it('should always return true', function () {
95+
assert.strictEqual(checkDefault(), true);
96+
});
97+
});
98+
99+
describe('checkMap usage examples', function () {
100+
it('checkMap.VariableDeclaration should call checkVarKindMatch internally and return correct boolean', function () {
101+
const node = { kind: 'const' };
102+
const astInfo = { kind: 'const' };
103+
const result = checkMap.VariableDeclaration(node, astInfo);
104+
assert.strictEqual(result, true);
105+
106+
const nodeMismatch = { kind: 'let' };
107+
const result2 = checkMap.VariableDeclaration(nodeMismatch, astInfo);
108+
assert.strictEqual(result2, false);
109+
});
110+
111+
it('checkMap.LogicalExpression should call checkOperatorMatch internally', function () {
112+
const node = { operator: '??' };
113+
const astInfo = { operator: '??' };
114+
const result = checkMap.LogicalExpression(node, astInfo);
115+
assert.strictEqual(result, true);
116+
});
117+
118+
it('checkMap.ArrowFunctionExpression should call checkDefault internally', function () {
119+
const result = checkMap.ArrowFunctionExpression();
120+
assert.strictEqual(result, true);
121+
});
122+
123+
it('checkMap.default should return false if node type is unsupported', function () {
124+
const result = checkMap.default();
125+
assert.strictEqual(result, false);
126+
});
127+
});
128+
129+
});

0 commit comments

Comments
 (0)