generated from bazel-contrib/rules-template
-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support --noEmit for type-checking as a validation action
- Loading branch information
1 parent
016923f
commit 0796649
Showing
16 changed files
with
194 additions
and
69 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
load "common.bats" | ||
|
||
setup() { | ||
cd $BATS_FILE_TMPDIR | ||
} | ||
|
||
teardown() { | ||
bazel shutdown | ||
rm -rf $BATS_FILE_TMPDIR/* | ||
} | ||
|
||
|
||
@test 'When tsc is only used for type-checking with a type-error, should pass when validations are disabled' { | ||
workspace | ||
|
||
echo "export const a: string = 1;" > ./source.ts | ||
tsconfig --declaration | ||
ts_project --transpiler-mock --declaration --src "source.ts" | ||
|
||
run bazel build :foo --norun_validations | ||
assert_success | ||
run cat bazel-bin/source.js | ||
assert_success | ||
# Mock transpiler just copies source input to output | ||
assert_output -p 'export const a: string = 1;' | ||
} | ||
|
||
@test 'When tsc is only used for type-checking with a type-error, should fail when validations are enabled' { | ||
workspace | ||
|
||
echo "export const a: string = 1;" > ./source.ts | ||
tsconfig --no-emit | ||
ts_project --no-emit --src "source.ts" | ||
|
||
run bazel build :foo --run_validations | ||
assert_failure | ||
assert_output -p "error TS2322: Type 'number' is not assignable to type 'string'" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
load("@aspect_rules_ts//ts:defs.bzl", "ts_project") | ||
load("@bazel_skylib//rules:write_file.bzl", "write_file") | ||
|
||
write_file( | ||
name = "gen_ts", | ||
out = "a.ts", | ||
content = [ | ||
"export const a: number = 42", | ||
], | ||
) | ||
|
||
# Shows how to run `tsc` producing no outputs at all. | ||
# It will use a validation action to type-check the file: | ||
# https://bazel.build/extending/rules#validation_actions | ||
# Run bazel with --norun_validations to skip type-checking. | ||
ts_project( | ||
name = "typecheck_only", | ||
srcs = ["a.ts"], | ||
no_emit = True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
// Workaround https://github.com/microsoft/TypeScript/issues/59036 | ||
"exclude": [], | ||
"compilerOptions": { | ||
"noEmit": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,19 @@ | ||
"""Only type-checks the input file, but does no transpilation or output any typings files. | ||
As such, it cannot run as a Bazel action under `bazel build`, as Bazel will only run actions when | ||
their outputs are requested. | ||
Therefore this is a test target and should be run with `bazel test`. | ||
Therefore type-checking is done with a validation action within the `ts_project` rule. | ||
""" | ||
|
||
load("@npm//examples:typescript/package_json.bzl", "bin") | ||
load("@aspect_rules_ts//ts:defs.bzl", "ts_project") | ||
|
||
bin.tsc_test( | ||
ts_project( | ||
name = "typecheck_only", | ||
args = [ | ||
"--noEmit", | ||
"$(location check-me.ts)", | ||
srcs = [ | ||
"check-me.ts", | ||
"lib.js", | ||
], | ||
data = ["check-me.ts"], | ||
# It should fail because we made a typing mistake | ||
# TypeScript ReturnCode: | ||
# OutputGeneratedWithErrors = 2, // .js and .map generated with semantic errors | ||
expected_exit_code = 2, | ||
tsconfig = { | ||
"compilerOptions": { | ||
"noEmit": True, | ||
}, | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
const a: number = 'a-string' | ||
// Ensure importing from .js works | ||
export * from './lib' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const a = 42 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.