mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
add Jest for TS unit tests
@hgiesel the reason no files were being found is because Jest ignores symlinks by default. The Bazel example includes a patch we can use to work around it, and Jest plan to add symlink support in a future update. https://github.com/bazelbuild/rules_nodejs/blob/stable/examples/jest/patches/jest-haste-map%2B24.9.0.patch https://github.com/facebook/jest/pull/9351
This commit is contained in:
parent
05ea624f85
commit
c891f45ed9
8 changed files with 3149 additions and 31 deletions
|
@ -23,6 +23,8 @@ exports_files([
|
|||
"licenses.json",
|
||||
"sql_format.ts",
|
||||
"protobuf-shim.js",
|
||||
"jest.config.js",
|
||||
"package.json",
|
||||
])
|
||||
|
||||
alias(
|
||||
|
|
|
@ -1,16 +1,47 @@
|
|||
load("@npm//@bazel/typescript:index.bzl", "ts_library")
|
||||
load("@npm//jest-cli:index.bzl", "jest_test")
|
||||
load("//ts:prettier.bzl", "prettier_test")
|
||||
load("//ts:eslint.bzl", "eslint_test")
|
||||
|
||||
ts_library(
|
||||
name = "html-filter",
|
||||
srcs = glob(["*.ts"]),
|
||||
srcs = glob(
|
||||
["*.ts"],
|
||||
exclude = ["*.test.ts"],
|
||||
),
|
||||
module_name = "html-filter",
|
||||
tsconfig = "//ts:tsconfig.json",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [],
|
||||
)
|
||||
|
||||
ts_library(
|
||||
name = "test_lib",
|
||||
srcs = glob(["*.test.ts"]),
|
||||
tsconfig = "//ts:tsconfig.json",
|
||||
deps = [
|
||||
"html-filter",
|
||||
"@npm//@types/jest",
|
||||
],
|
||||
)
|
||||
|
||||
jest_test(
|
||||
name = "test",
|
||||
args = [
|
||||
"--no-cache",
|
||||
"--no-watchman",
|
||||
"--ci",
|
||||
"--colors",
|
||||
"--config",
|
||||
"$(location //ts:jest.config.js)",
|
||||
],
|
||||
data = [
|
||||
":test_lib",
|
||||
"//ts:jest.config.js",
|
||||
"//ts:package.json",
|
||||
],
|
||||
)
|
||||
|
||||
# Tests
|
||||
################
|
||||
|
||||
|
|
3
ts/html-filter/index.test.ts
Normal file
3
ts/html-filter/index.test.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
test("it should work", () => {
|
||||
expect("test").toBe("test");
|
||||
});
|
0
ts/jest.config.js
Normal file
0
ts/jest.config.js
Normal file
|
@ -14,6 +14,7 @@
|
|||
"@tsconfig/svelte": "^1.0.10",
|
||||
"@types/d3": "^6.3.0",
|
||||
"@types/diff": "^5.0.0",
|
||||
"@types/jest": "^26.0.22",
|
||||
"@types/jquery": "^3.5.0",
|
||||
"@types/jqueryui": "^1.12.13",
|
||||
"@types/lodash": "^4.14.162",
|
||||
|
@ -32,9 +33,11 @@
|
|||
"espree": "^7.3.1",
|
||||
"estraverse": "^5.2.0",
|
||||
"glob": "^7.1.6",
|
||||
"jest-cli": "^24.9",
|
||||
"jsdoc": "^3.6.6",
|
||||
"license-checker-rseidelsohn": "=1.1.2",
|
||||
"minimist": "^1.2.5",
|
||||
"patch-package": "^6.4.7",
|
||||
"prettier": "^2.1.2",
|
||||
"prettier-plugin-svelte": "^1.4.0",
|
||||
"sass": "^1.32.6",
|
||||
|
@ -49,7 +52,8 @@
|
|||
"uglify-js": "^3.13.1"
|
||||
},
|
||||
"scripts": {
|
||||
"fix": "prettier --write */*.ts */*.svelte"
|
||||
"fix": "prettier --write */*.ts */*.svelte",
|
||||
"postinstall": "patch-package"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fluent/bundle": "^0.15.1",
|
||||
|
|
16
ts/patches/jest-haste-map+24.9.0.patch
Normal file
16
ts/patches/jest-haste-map+24.9.0.patch
Normal file
|
@ -0,0 +1,16 @@
|
|||
diff --git a/node_modules/jest-haste-map/build/crawlers/node.js b/node_modules/jest-haste-map/build/crawlers/node.js
|
||||
index 23985ae..a728a9a 100644
|
||||
--- a/node_modules/jest-haste-map/build/crawlers/node.js
|
||||
+++ b/node_modules/jest-haste-map/build/crawlers/node.js
|
||||
@@ -166,7 +166,11 @@ function find(roots, extensions, ignore, callback) {
|
||||
|
||||
function findNative(roots, extensions, ignore, callback) {
|
||||
const args = Array.from(roots);
|
||||
+ args.push('(');
|
||||
args.push('-type', 'f');
|
||||
+ args.push('-o');
|
||||
+ args.push('-type', 'l');
|
||||
+ args.push(')');
|
||||
|
||||
if (extensions.length) {
|
||||
args.push('(');
|
|
@ -26,7 +26,7 @@
|
|||
"allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
|
||||
"jsx": "react",
|
||||
"types": ["svelte", "long", "node"],
|
||||
"types": ["svelte", "long", "node", "jest"],
|
||||
"noEmitHelpers": true,
|
||||
"importHelpers": true
|
||||
}
|
||||
|
|
3118
ts/yarn.lock
3118
ts/yarn.lock
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue