Skip to content

Commit 775f4b4

Browse files
committed
use jest instead of mocha
1 parent 68082bb commit 775f4b4

13 files changed

+4922
-3820
lines changed

Diff for: .jest.config.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
verbose: true,
3+
4+
setupFilesAfterEnv: ["./tests/setup.js"],
5+
6+
moduleFileExtensions: ["ts", "tsx", "js", "jsx"],
7+
8+
transform: {
9+
"^.+\\.tsx?$": ["babel-jest", { configFile: "./tests/.babelrc.js" }],
10+
},
11+
12+
testRegex: ".*\\.test\\.(j|t)sx?$",
13+
14+
moduleNameMapper: {
15+
"@/(.*)$": "<rootDir>/src/$1",
16+
"tests/(.*)$": "<rootDir>/tests/$1",
17+
},
18+
}

Diff for: .mocharc.json

-5
This file was deleted.

Diff for: package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
"react-dom": "^16.13.1",
1414
"react-redux": "^7.2.1",
1515
"react-router-dom": "^5.2.0",
16-
"react-scripts": "3.4.3",
16+
"react-scripts": "4.0.3",
1717
"regexpp": "Bowen7/regexpp#8fb9c550810a37b8c4486cc547635518a2e4f57e",
1818
"styled-jsx": "3.3.0",
1919
"typescript": "~3.7.2"
2020
},
2121
"scripts": {
2222
"start": "react-app-rewired start",
2323
"build": "react-app-rewired build",
24-
"test": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha",
24+
"test": "jest --config .jest.config.js --no-cache",
2525
"eject": "react-scripts eject",
2626
"build:graph": "rm -rf dest && rollup -c",
2727
"export:svg": "npm run build:graph && node scripts/export.js"
@@ -51,7 +51,7 @@
5151
"@rollup/plugin-node-resolve": "^13.0.0",
5252
"@rollup/plugin-replace": "^2.4.2",
5353
"@svgr/webpack": "^5.5.0",
54-
"@types/jest": "^24.0.0",
54+
"@types/jest": "^24.9.1",
5555
"@types/lodash": "^4.14.168",
5656
"@types/node": "^12.0.0",
5757
"@types/react": "^16.9.0",
@@ -61,7 +61,7 @@
6161
"@types/styled-jsx": "^2.2.8",
6262
"babel-plugin-import": "^1.13.3",
6363
"customize-cra": "^1.0.0",
64-
"mocha": "^9.0.1",
64+
"jest": "^26.6.0",
6565
"react-app-rewired": "^2.1.6",
6666
"rollup": "^2.48.0",
6767
"ts-node": "^10.0.0"

Diff for: paths.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"compilerOptions": {
33
"baseUrl": "src",
44
"paths": {
5-
"@/*":["*"]
5+
"@/*": ["*"],
6+
"tests/*": ["../tests/*"]
67
}
78
}
8-
}
9+
}

Diff for: pnpm-lock.yaml

+4,734-3,758
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: scripts/figma.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const React = require("react")
2+
const ReactDOMServer = require("react-dom/server")
3+
const MinimumGraph = require("../dest/index.js")
4+
let string = ReactDOMServer.renderToString(
5+
React.createElement(MinimumGraph, {
6+
regex: "/([a-zA-Z_])*?@[a-zA-Z](\\.[a-zA-Z-]{0,10})?(a|b)/",
7+
selected: false,
8+
})
9+
)
10+
11+
string = string
12+
.replace(/class="stroke"/g, `stroke="#000"`)
13+
.replace(
14+
/class="transparent-fill stroke"/g,
15+
`fill="rgba(255,255,255,0)" stroke="#000"`
16+
)
17+
.replace(
18+
/class="second-stroke transparent-fill"/g,
19+
`fill="rgba(255,255,255,0)" stroke="#444"`
20+
)
21+
.replace(
22+
/class="transparent-fill second-stroke"/g,
23+
`fill="rgba(255,255,255,0)" stroke="#444"`
24+
)
25+
.replace(/class="transparent-fill"/g, `fill="rgba(255,255,255,0)"`)
26+
.replace(
27+
/class="transparent-fill none-stroke"/g,
28+
`fill="rgba(255,255,255,0)" stroke="none"`
29+
)
30+
.replace(/class="text"/g, `fill="#000"`)
31+
.replace(/<g><g>/g, ``)
32+
.replace(/<\/g><\/g>/g, ``)
33+
console.log(string)

Diff for: src/parser/__tests__/parse.json

+61-8
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
{ "type": "root" },
44
{
55
"type": "character",
6-
"value": { "type": "string", "value": "a" },
7-
"texts": ["a"]
6+
"value": { "kind": "string", "value": "a" }
87
},
98
{ "type": "root" }
109
],
1110
"/abc/": [
1211
{ "type": "root" },
1312
{
1413
"type": "character",
15-
"value": { "type": "string", "value": "abc" },
16-
"texts": ["abc"]
14+
"value": { "kind": "string", "value": "abc" }
1715
},
1816
{ "type": "root" }
1917
],
@@ -22,12 +20,67 @@
2220
{
2321
"type": "character",
2422
"value": {
25-
"type": "ranges",
23+
"kind": "ranges",
2624
"value": [{ "from": "a", "to": "b" }],
2725
"negate": false
28-
},
29-
"texts": ["a - b"],
30-
"name": "One of "
26+
}
27+
},
28+
{ "type": "root" }
29+
],
30+
"/[a]/": [
31+
{ "type": "root" },
32+
{
33+
"type": "character",
34+
"value": {
35+
"kind": "ranges",
36+
"value": [{ "from": "a", "to": "a" }],
37+
"negate": false
38+
}
39+
},
40+
{ "type": "root" }
41+
],
42+
"/[a-bb-c]/": [
43+
{ "type": "root" },
44+
{
45+
"type": "character",
46+
"value": {
47+
"kind": "ranges",
48+
"value": [
49+
{ "from": "a", "to": "b" },
50+
{ "from": "b", "to": "c" }
51+
],
52+
"negate": false
53+
}
54+
},
55+
{ "type": "root" }
56+
],
57+
"/[a-bc]/": [
58+
{ "type": "root" },
59+
{
60+
"type": "character",
61+
"value": {
62+
"kind": "ranges",
63+
"value": [
64+
{ "from": "a", "to": "b" },
65+
{ "from": "c", "to": "c" }
66+
],
67+
"negate": false
68+
}
69+
},
70+
{ "type": "root" }
71+
],
72+
"/[^a-bc]/": [
73+
{ "type": "root" },
74+
{
75+
"type": "character",
76+
"value": {
77+
"kind": "ranges",
78+
"value": [
79+
{ "from": "a", "to": "b" },
80+
{ "from": "c", "to": "c" }
81+
],
82+
"negate": true
83+
}
3184
},
3285
{ "type": "root" }
3386
]

Diff for: src/parser/__tests__/parse.spec.ts

-41
This file was deleted.

Diff for: src/parser/__tests__/parse.test.ts

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { removeFields } from "tests/utils"
2+
import parse from "../parse"
3+
import parseJson from "./parse.json"
4+
5+
const p = (regex: string) => {
6+
return removeFields(parse(regex), ["id"])
7+
}
8+
9+
describe("Parse Regex String", function () {
10+
describe("Character", function () {
11+
it("single character", function () {
12+
const r = "/a/"
13+
expect(p(r)).toEqual(parseJson[r])
14+
})
15+
16+
it("multiple character", function () {
17+
const r = "/abc/"
18+
expect(p(r)).toEqual(parseJson[r])
19+
})
20+
21+
it("normal range", function () {
22+
const r = "/[a-b]/"
23+
expect(p(r)).toEqual(parseJson[r])
24+
})
25+
26+
it("single range", function () {
27+
const r = "/[a]/"
28+
expect(p(r)).toEqual(parseJson[r])
29+
})
30+
31+
it("multiple range1", function () {
32+
const r = "/[a-bb-c]/"
33+
expect(p(r)).toEqual(parseJson[r])
34+
})
35+
36+
it("multiple range2", function () {
37+
const r = "/[a-bc]/"
38+
expect(p(r)).toEqual(parseJson[r])
39+
})
40+
41+
it("negate range", function () {
42+
const r = "/[^a-bc]/"
43+
expect(p(r)).toEqual(parseJson[r])
44+
})
45+
})
46+
})

Diff for: tests/.babelrc.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
presets: ["@babel/env", "@babel/react", "@babel/typescript"],
3+
plugins: ["styled-jsx/babel-test"],
4+
}

Diff for: tests/setup.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Diff for: tests/utils.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const removeFields = (target: any, fields: string[]) => {
2+
if (Array.isArray(target)) {
3+
target.forEach((item) => removeFields(item, fields))
4+
} else if ({}.toString.call(target) === "[object Object]") {
5+
Object.keys(target).forEach((key) => {
6+
if (fields.includes(key)) {
7+
delete target[key]
8+
} else {
9+
removeFields(target[key], fields)
10+
}
11+
})
12+
}
13+
return target
14+
}

Diff for: tsconfig.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
"resolveJsonModule": true,
1818
"isolatedModules": true,
1919
"noEmit": true,
20-
"jsx": "react"
20+
"jsx": "react",
21+
"noFallthroughCasesInSwitch": true
2122
},
2223
"include": [
23-
"src"
24+
"src",
25+
"tests"
2426
],
2527
"extends": "./paths.json"
2628
}

0 commit comments

Comments
 (0)