Skip to content

Commit

Permalink
Merge 4760353 into 66633d5
Browse files Browse the repository at this point in the history
  • Loading branch information
huafu committed Sep 10, 2018
2 parents 66633d5 + 4760353 commit 0e7dc36
Show file tree
Hide file tree
Showing 25 changed files with 391 additions and 87 deletions.
19 changes: 10 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ node_js:
sudo: false

before_install:
# Disabled, randomly works :-/
# https://github.com/scikit-learn/scikit-learn/issues/10927
- |
set -e
# fail loudly when force-pushed, that is why there is the `|| 'dummy.js'` part
MODIFIED_FILES=$(git diff --name-only $TRAVIS_COMMIT_RANGE || echo 'dummy.js')
# waiting for native solution https://github.com/travis-ci/travis-ci/issues/6301
if ! echo ${MODIFIED_FILES} | grep -qvE '^docs/|^\.gitignore|^\.gitattributes|\.md$|^appveyor\.yml$|^icon\.png$|^commitlint\.config\.js$'; then
echo "Only docs were updated, stopping build process."
exit
fi
# - |
# set -e
# # fail loudly when force-pushed, that is why there is the `|| 'dummy.js'` part
# MODIFIED_FILES=$(git diff --name-only $TRAVIS_COMMIT_RANGE || echo 'dummy.js')
# # waiting for native solution https://github.com/travis-ci/travis-ci/issues/6301
# if ! echo ${MODIFIED_FILES} | grep -qvE '^docs/|^\.gitignore|^\.gitattributes|\.md$|^appveyor\.yml$|^icon\.png$|^commitlint\.config\.js$'; then
# echo "Only docs were updated, stopping build process."
# exit
# fi
# ensure we have npm >= 5.8 so that we can use `npm ci` instead of `npm install` (much faster)
- dpkg --compare-versions `npm -v` ge 5.8 || npm i -g npm@latest
# we report coverages only within node 10, ensure we have the coveralls bin installed
Expand Down
22 changes: 11 additions & 11 deletions docs/tech/process/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ if (filename ends with .d.ts) then (yes)
else (no)

|#Thistle|compiler (cached)|
if (has type-checking?) then (yes)
if (isolated modules?) then (yes)
else (no)
:create and cache
ts lang service;
else (no)
endif

-> source;
Expand All @@ -73,7 +73,15 @@ else (no)
from persistent cache;

else (no)
if (has type checking?) then (yes)
if (isolated modules?) then (yes)
:compile with
transpileModule;
note left
files will be compiled
as isolated modules
end note

else (no)
:compile with
service;
note left
Expand All @@ -84,14 +92,6 @@ else (no)
reading files
end note

else (no)
:compile with
transpileModule;
note left
files will be compiled
as isolated modules
end note

endif

:custom AST
Expand Down
53 changes: 47 additions & 6 deletions docs/user/config/diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@ A diagnostic can be:
- syntax errors in some of your TypeScript files (source or tests)
- type/semantic errors, what TypeScript has actually been made for 😁

If a diagnostic is not filtered out, it'll fail the compilatin within TSJest, and so will your related test.
If a diagnostic is not filtered out, it'll fail the compilation within TSJest, and so will your related test.

### Disabling/enabling

By default all diagnostic are enabled. This is the same as setting the `diagnostics` option to `true`. To disable all diagnostics, set `diagnostics` to `false` (you might experience slightly better performence as well, especially if you disabled Jest cache).
By default all diagnostic are enabled. This is the same as setting the `diagnostics` option to `true`. To disable all diagnostics, set `diagnostics` to `false` (you might experience slightly better performance as well, especially if you disabled Jest cache).

### Advanced configuration

The option's value can also accpet an object for more advanced configuration. Each config. key is optional:
The option's value can also accept an object for more advanced configuration. Each config. key is optional:

- **`pretty`**: Enables/disable colorful and pretty output of errors (default: _enabled_).
- **`warnOnly`**: If specified and `true`, diagnostics will be reported but won't stop compilation (default: _disabled_).
- **`ignoreCodes`**: List of TypeScript error codes to ignore. Complete list can be found [there](https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json). By default here are the ones ignored:
- `6059`: _'rootDir' is expected to contain all source files._
- `18002`: _The 'files' list in config file is empty._ (it is strongly recommanded to include this one)
- `18002`: _The 'files' list in config file is empty._ (it is strongly recommended to include this one)
- `18003`: _No inputs were found in config file._
- **`pathRegex`**: If specified, diagnostics of source files which path does **not** match will be ignored.
- **`pretty`**: Enables/disables colorful and pretty output of errors (default: _enabled_).

### Examples

Expand Down Expand Up @@ -77,7 +78,7 @@ module.exports = {
globals: {
'ts-jest': {
diagnostics: {
pathRegex: /\.(spec|test).ts$/
pathRegex: /\.(spec|test)\.ts$/
}
}
}
Expand All @@ -104,6 +105,46 @@ module.exports = {

</div></div>

##### Do not fail on first error

While some diagnostics are stop-blockers for the compilation, most of them are not. If you want the compilation (and so your tests) to continue when encountering those, set the `warnOnly` to `true`:

<div class="row"><div class="col-md-6" markdown="block">

```js
// jest.config.js
module.exports = {
// [...]
globals: {
'ts-jest': {
diagnostics: {
warnOnly: true
}
}
}
};
```

</div><div class="col-md-6" markdown="block">

```js
// OR package.json
{
// [...]
"jest": {
"globals": {
"ts-jest": {
"diagnostics": {
"warnOnly": true
}
}
}
}
}
```

</div></div>

##### Ignoring some error codes:

All TypeScript error codes can be found [there](https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json). The `ignoreCodes` option accepts this values:
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`With type checking should fail using template "default" 1`] = `
exports[`With diagnostics, first throws should fail using template "default" 1`] = `
× jest
↳ exit code: 1
===[ STDOUT ]===================================================================
Expand All @@ -9,7 +9,7 @@ exports[`With type checking should fail using template "default" 1`] = `
FAIL ./main.spec.ts
● Test suite failed to run
Unable to compile TypeScript (add code(s) in \`[jest-config].globals.ts-jest.diagnostics.ignoreCodes\` to ignore):
TypeScript diagnostics (customize using \`[jest-config].globals.ts-jest.diagnostics\` option):
main.ts:2:3 - error TS2322: Type 'string' is not assignable to type 'number'.
2 return input
Expand All @@ -23,7 +23,7 @@ exports[`With type checking should fail using template "default" 1`] = `
================================================================================
`;

exports[`With type checking should fail using template "with-babel-6" 1`] = `
exports[`With diagnostics, first throws should fail using template "with-babel-6" 1`] = `
× jest
↳ exit code: 1
===[ STDOUT ]===================================================================
Expand All @@ -32,7 +32,7 @@ exports[`With type checking should fail using template "with-babel-6" 1`] = `
FAIL ./main.spec.ts
● Test suite failed to run
Unable to compile TypeScript (add code(s) in \`[jest-config].globals.ts-jest.diagnostics.ignoreCodes\` to ignore):
TypeScript diagnostics (customize using \`[jest-config].globals.ts-jest.diagnostics\` option):
main.ts:2:3 - error TS2322: Type 'string' is not assignable to type 'number'.
2 return input
Expand All @@ -46,7 +46,7 @@ exports[`With type checking should fail using template "with-babel-6" 1`] = `
================================================================================
`;

exports[`With type checking should fail using template "with-babel-7" 1`] = `
exports[`With diagnostics, first throws should fail using template "with-babel-7" 1`] = `
× jest
↳ exit code: 1
===[ STDOUT ]===================================================================
Expand All @@ -55,7 +55,7 @@ exports[`With type checking should fail using template "with-babel-7" 1`] = `
FAIL ./main.spec.ts
● Test suite failed to run
Unable to compile TypeScript (add code(s) in \`[jest-config].globals.ts-jest.diagnostics.ignoreCodes\` to ignore):
TypeScript diagnostics (customize using \`[jest-config].globals.ts-jest.diagnostics\` option):
main.ts:2:3 - error TS2322: Type 'string' is not assignable to type 'number'.
2 return input
Expand All @@ -69,7 +69,7 @@ exports[`With type checking should fail using template "with-babel-7" 1`] = `
================================================================================
`;

exports[`With type checking should fail using template "with-jest-22" 1`] = `
exports[`With diagnostics, first throws should fail using template "with-jest-22" 1`] = `
× jest
↳ exit code: 1
===[ STDOUT ]===================================================================
Expand All @@ -78,7 +78,7 @@ exports[`With type checking should fail using template "with-jest-22" 1`] = `
FAIL ./main.spec.ts
● Test suite failed to run
Unable to compile TypeScript (add code(s) in \`[jest-config].globals.ts-jest.diagnostics.ignoreCodes\` to ignore):
TypeScript diagnostics (customize using \`[jest-config].globals.ts-jest.diagnostics\` option):
main.ts:2:3 - error TS2322: Type 'string' is not assignable to type 'number'.
2 return input
Expand All @@ -92,7 +92,7 @@ exports[`With type checking should fail using template "with-jest-22" 1`] = `
================================================================================
`;

exports[`With type checking should fail using template "with-typescript-2-7" 1`] = `
exports[`With diagnostics, first throws should fail using template "with-typescript-2-7" 1`] = `
× jest
↳ exit code: 1
===[ STDOUT ]===================================================================
Expand All @@ -101,7 +101,7 @@ exports[`With type checking should fail using template "with-typescript-2-7" 1`]
FAIL ./main.spec.ts
● Test suite failed to run
Unable to compile TypeScript (add code(s) in \`[jest-config].globals.ts-jest.diagnostics.ignoreCodes\` to ignore):
TypeScript diagnostics (customize using \`[jest-config].globals.ts-jest.diagnostics\` option):
main.ts:2:3 - error TS2322: Type 'string' is not assignable to type 'number'.
2 return input
Expand All @@ -115,12 +115,17 @@ exports[`With type checking should fail using template "with-typescript-2-7" 1`]
================================================================================
`;

exports[`Without type checking should pass using template "default" 1`] = `
√ jest --config {"preset":"ts-jest","testEnvironment":"node","globals":{"ts-jest":{"tsConfig":{},"isolatedModules":true}}}
exports[`With diagnostics, warn only should pass using template "default" 1`] = `
√ jest --config {"preset":"ts-jest","testEnvironment":"node","globals":{"ts-jest":{"tsConfig":{},"diagnostics":{"warnOnly":true}}}}
↳ exit code: 0
===[ STDOUT ]===================================================================
===[ STDERR ]===================================================================
ts-jest[ts-compiler] (WARN) TypeScript diagnostics (customize using \`[jest-config].globals.ts-jest.diagnostics\` option):
main.ts:2:3 - error TS2322: Type 'string' is not assignable to type 'number'.
2 return input
~~~~~~~~~~~~
PASS ./main.spec.ts
√ should pass
Expand All @@ -132,12 +137,17 @@ exports[`Without type checking should pass using template "default" 1`] = `
================================================================================
`;

exports[`Without type checking should pass using template "with-babel-6" 1`] = `
√ jest --config {"preset":"ts-jest","testEnvironment":"node","globals":{"ts-jest":{"tsConfig":{},"babelConfig":true,"isolatedModules":true}}}
exports[`With diagnostics, warn only should pass using template "with-babel-6" 1`] = `
√ jest --config {"preset":"ts-jest","testEnvironment":"node","globals":{"ts-jest":{"tsConfig":{},"babelConfig":true,"diagnostics":{"warnOnly":true}}}}
↳ exit code: 0
===[ STDOUT ]===================================================================
===[ STDERR ]===================================================================
ts-jest[ts-compiler] (WARN) TypeScript diagnostics (customize using \`[jest-config].globals.ts-jest.diagnostics\` option):
main.ts:2:3 - error TS2322: Type 'string' is not assignable to type 'number'.
2 return input
~~~~~~~~~~~~
PASS ./main.spec.ts
√ should pass
Expand All @@ -149,12 +159,17 @@ exports[`Without type checking should pass using template "with-babel-6" 1`] = `
================================================================================
`;

exports[`Without type checking should pass using template "with-babel-7" 1`] = `
√ jest --config {"preset":"ts-jest","testEnvironment":"node","globals":{"ts-jest":{"tsConfig":{},"babelConfig":true,"isolatedModules":true}}}
exports[`With diagnostics, warn only should pass using template "with-babel-7" 1`] = `
√ jest --config {"preset":"ts-jest","testEnvironment":"node","globals":{"ts-jest":{"tsConfig":{},"babelConfig":true,"diagnostics":{"warnOnly":true}}}}
↳ exit code: 0
===[ STDOUT ]===================================================================
===[ STDERR ]===================================================================
ts-jest[ts-compiler] (WARN) TypeScript diagnostics (customize using \`[jest-config].globals.ts-jest.diagnostics\` option):
main.ts:2:3 - error TS2322: Type 'string' is not assignable to type 'number'.
2 return input
~~~~~~~~~~~~
PASS ./main.spec.ts
√ should pass
Expand All @@ -166,12 +181,17 @@ exports[`Without type checking should pass using template "with-babel-7" 1`] = `
================================================================================
`;

exports[`Without type checking should pass using template "with-jest-22" 1`] = `
√ jest --config {"transform":{"^.+\\\\.tsx?$":"ts-jest"},"testMatch":["**/__tests__/**/*.js?(x)","**/?(*.)+(spec|test).js?(x)","**/__tests__/**/*.ts?(x)","**/?(*.)+(spec|test).ts?(x)"],"moduleFileExtensions":["js","json","jsx","node","ts","tsx"],"testEnvironment":"node","globals":{"ts-jest":{"tsConfig":{},"isolatedModules":true}}}
exports[`With diagnostics, warn only should pass using template "with-jest-22" 1`] = `
√ jest --config {"transform":{"^.+\\\\.tsx?$":"ts-jest"},"testMatch":["**/__tests__/**/*.js?(x)","**/?(*.)+(spec|test).js?(x)","**/__tests__/**/*.ts?(x)","**/?(*.)+(spec|test).ts?(x)"],"moduleFileExtensions":["js","json","jsx","node","ts","tsx"],"testEnvironment":"node","globals":{"ts-jest":{"tsConfig":{},"diagnostics":{"warnOnly":true}}}}
↳ exit code: 0
===[ STDOUT ]===================================================================
===[ STDERR ]===================================================================
ts-jest[ts-compiler] (WARN) TypeScript diagnostics (customize using \`[jest-config].globals.ts-jest.diagnostics\` option):
main.ts:2:3 - error TS2322: Type 'string' is not assignable to type 'number'.
2 return input
~~~~~~~~~~~~
PASS ./main.spec.ts
√ should pass
Expand All @@ -183,12 +203,17 @@ exports[`Without type checking should pass using template "with-jest-22" 1`] = `
================================================================================
`;

exports[`Without type checking should pass using template "with-typescript-2-7" 1`] = `
√ jest --config {"preset":"ts-jest","testEnvironment":"node","globals":{"ts-jest":{"tsConfig":{},"diagnostics":{"ignoreCodes":[5023]},"isolatedModules":true}}}
exports[`With diagnostics, warn only should pass using template "with-typescript-2-7" 1`] = `
√ jest --config {"preset":"ts-jest","testEnvironment":"node","globals":{"ts-jest":{"tsConfig":{},"diagnostics":{"ignoreCodes":[5023],"warnOnly":true}}}}
↳ exit code: 0
===[ STDOUT ]===================================================================
===[ STDERR ]===================================================================
ts-jest[ts-compiler] (WARN) TypeScript diagnostics (customize using \`[jest-config].globals.ts-jest.diagnostics\` option):
main.ts:2:3 - error TS2322: Type 'string' is not assignable to type 'number'.
2 return input
~~~~~~~~~~~~
PASS ./main.spec.ts
√ should pass
Expand Down

0 comments on commit 0e7dc36

Please sign in to comment.