Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ example_integration_test(

example_integration_test(
name = "examples_jest",
npm_packages = {
"//packages/typescript:npm_package": "@bazel/typescript",
},
)

example_integration_test(
Expand Down
19 changes: 18 additions & 1 deletion examples/jest/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
load(":jest.bzl", "jest_test")
load("@npm_bazel_typescript//:index.bzl", "ts_library")
load(":jest.bzl", "jest_test", "ts_jest_test")

ts_library(
name = "lib",
srcs = ["lib.ts"],
)

jest_test(
name = "test",
Expand Down Expand Up @@ -26,6 +32,17 @@ jest_test(
],
)

ts_jest_test(
name = "test_ts",
srcs = [
"lib.test.ts",
],
jest_config = "jest.config.js",
deps = [
":lib",
],
)

# Just a dummy test so that we have a test target for //... on certain bazelci platforms with bazel_integration_test
sh_test(
name = "dummy_test",
Expand Down
33 changes: 33 additions & 0 deletions examples/jest/jest.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"Shows how you might create a macro for the autogeneratd Jest rule"

load("@npm//jest-cli:index.bzl", _jest_test = "jest_test")
load("@npm_bazel_typescript//:index.bzl", "ts_library")

def jest_test(name, srcs, deps, jest_config, **kwargs):
"A macro around the autogenerated jest_test rule"
Expand All @@ -19,3 +20,35 @@ def jest_test(name, srcs, deps, jest_config, **kwargs):
templated_args = templated_args,
**kwargs
)

def ts_jest_test(name, srcs, jest_config, deps = [], data = [], **kwargs):
"A macro around the autogenerated jest_test rule"

ts_library(
name = "%s_ts" % name,
srcs = srcs,
data = data,
deps = deps + ["@npm//@types/jest"],
)
native.filegroup(
name = "%s_es5" % name,
srcs = [":%s_ts" % name],
output_group = "es5_sources",
)

args = [
"--no-cache",
"--no-watchman",
"--ci",
]
args.extend(["--config", "$(rootpath %s)" % jest_config])

for src in srcs:
args.extend(["--runTestsByPath", "$(rootpath :%s_es5)" % name])

_jest_test(
name = name,
data = [jest_config, ":%s_es5" % name] + deps + data,
args = args,
**kwargs
)
7 changes: 7 additions & 0 deletions examples/jest/lib.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {echo} from './lib';

describe('echo', () => {
it('should return input', () => {
expect(echo('boom')).toContain('boom');
});
});
3 changes: 3 additions & 0 deletions examples/jest/lib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function echo(a: string): string {
return a
}
5 changes: 4 additions & 1 deletion examples/jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
"@babel/cli": "^7.6.0",
"@babel/core": "^7.6.0",
"@babel/preset-env": "^7.6.0",
"@bazel/typescript": "^1.6.0",
"@jest/core": "24.7.1",
"@jest/transform": "24.7.1",
"@types/jest": "^25.2.1",
"babel-jest": "24.7.1",
"babel-plugin-istanbul": "5.1.2",
"jest-cli": "24.9.0",
"patch-package": "^6.2.0"
"patch-package": "^6.2.0",
"typescript": "^3.8.3"
},
"scripts": {
"postinstall": "patch-package",
Expand Down
26 changes: 26 additions & 0 deletions examples/jest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"declaration": true,
"target": "es2018",
"module": "commonjs",
"lib": [
"ESNext.AsyncIterable",
"ES2018",
"DOM",
"ES6"
],
"outDir": "dist",
"baseUrl": "./",
"paths": {
"jest_repro/*": [
"*",
"bazel-bin/*"
]
},
"removeComments": true,
"strict": true,
"esModuleInterop": true,
"downlevelIteration": true,
"forceConsistentCasingInFileNames": true
}
}
Loading