Skip to content
This repository was archived by the owner on Dec 3, 2024. It is now read-only.

Commit 99f1f9e

Browse files
author
Lorenzo Kappeler
authored
chore: update test suite (#9)
* test: add test cases for deep require * -: add default test command * -: lint if internal modules are imported * -: test all variations of the linter * chore: try to lint the type import * chore: note the bug and adapt the test suite
1 parent 75e8ddb commit 99f1f9e

File tree

9 files changed

+72
-23
lines changed

9 files changed

+72
-23
lines changed

.eslintrc.node.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
extends: ["./react.js"],
3+
overrides: [
4+
{
5+
files: ["packMain.js"],
6+
parser: "esprima",
7+
},
8+
],
9+
}

.eslintrc.react.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
extends: ["./react.js"],
3+
overrides: [
4+
{
5+
files: ["packMain.js"],
6+
parser: "esprima",
7+
},
8+
],
9+
}

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,6 @@ module.exports = {
100100
"sort-keys": "off",
101101
"no-console": "error",
102102
"json/*": "error",
103+
"import/no-internal-modules": "error",
103104
},
104105
}

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"build": "pika build",
88
"lint": "eslint --ext ts,js,tsx,jsx,json .",
99
"format": "npm run lint -- --fix",
10+
"test": "npm run test:unit",
1011
"test:unit": "./test/test.sh"
1112
},
1213
"repository": {
@@ -36,6 +37,7 @@
3637
"tslint": "^6.1.2"
3738
},
3839
"devDependencies": {
40+
"@carforyou/api-client": "^16.1.0",
3941
"@pika/pack": "^0.5.0",
4042
"@pika/plugin-copy-assets": "^0.9.2",
4143
"@pika/plugin-standard-pkg": "^0.9.2",

test/bad/js/internal-modules.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2+
import picka from "@pika/pack/dist-src/index"

test/bad/ts/internal-modules.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2+
import picka from "@pika/pack/dist-src/index"
3+
// There is probably a bug with type imports:
4+
// https://github.com/benmosher/eslint-plugin-import/issues/1880
5+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
6+
import { Entitlements } from "@carforyou/api-client/dist-types/types/models"

test/test.sh

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
11
#!/usr/bin/env bash
22

3-
bad_expected=14
4-
good_expected=0
5-
6-
bad_output=$(npx eslint --ignore-path .eslintignore.test --format json "test/bad/**/*")
7-
echo $bad_output
8-
9-
bad_failures=$(echo $bad_output | npx jq ". | map(.errorCount) | add")
10-
11-
if [ "$bad_failures" != "$bad_expected" ]; then
12-
echo "Expected $bad_expected but got $bad_failures linting errors for badly formatted files"
13-
exit 1
14-
fi
15-
16-
17-
good_output=$(npx eslint --ignore-path .eslintignore.test --format json "test/good/**/*")
18-
echo $good_output
19-
20-
good_failures=$(echo $good_output | npx jq ". | map(.errorCount) | add")
21-
22-
if [ "$good_failures" != "$good_expected" ]; then
23-
echo "Expected $good_expected but got $good_failures linting errors for well formatted files"
24-
exit 1
25-
fi
3+
${PWD}/test/testRunner.sh -c .eslintrc.js -g 0 -b 16
4+
${PWD}/test/testRunner.sh -c .eslintrc.react.js -g 0 -b 18
5+
${PWD}/test/testRunner.sh -c .eslintrc.node.js -g 0 -b 18

test/testRunner.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
3+
while getopts c:g:b: option
4+
do
5+
case "${option}"
6+
in
7+
c) CONFIG=${OPTARG};;
8+
g) good_expected=${OPTARG};;
9+
b) bad_expected=${OPTARG};;
10+
esac
11+
done
12+
13+
bad_output=$(npx eslint --config ${CONFIG} --ignore-path .eslintignore.test --format json "test/bad/**/*")
14+
echo "Bad Test Cases:"
15+
echo -n $bad_output | npx jq .
16+
17+
bad_failures=$(echo $bad_output | npx jq ". | map(.errorCount) | add")
18+
19+
if [ "$bad_failures" != "$bad_expected" ]; then
20+
echo "Expected $bad_expected but got $bad_failures linting errors for badly formatted files"
21+
exit 1
22+
fi
23+
24+
25+
good_output=$(npx eslint --ignore-path .eslintignore.test --format json "test/good/**/*")
26+
echo "Good Test Cases:"
27+
echo -n $good_output | npx jq .
28+
29+
good_failures=$(echo $good_output | npx jq ". | map(.errorCount) | add")
30+
31+
if [ "$good_failures" != "$good_expected" ]; then
32+
echo -n "Expected $good_expected with CONFIG: ${CONFIG} but got $good_failures linting errors for well formatted files"
33+
exit 1
34+
fi

0 commit comments

Comments
 (0)