You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Jest is the main test runner that this package supports.
69
73
70
74
### Test files
75
+
71
76
Everything that matches the globs below will be passed to Jest as a test file:
77
+
72
78
-`src/**/__tests__/**/*.(j|t)s?(x)`
73
79
-`src/**/?(*.)(spec|test|t).(j|t)s?(x)`
74
80
75
81
### Setting up the test framework
82
+
76
83
You can use `setupTests.ts` in your project root to set up the testing framework before each test.
77
84
78
85
### Overriding Jest configuration
86
+
79
87
You can override the Jest configuration in your `package.json` with the key `jest`.
80
88
81
89
The following options can be overriden:
90
+
82
91
-`collectCoverageFrom`
83
92
-`coverageReporters`
84
93
-`coverageThreshold`
85
94
86
95
## Custom Module Paths
96
+
87
97
TNS supports custom module path mappings. A default custom path mapping is provided in `tsconfig.json`
88
98
89
99
```json
90
100
{
91
-
"paths": {
92
-
"~/*": ["src/*"]
93
-
}
101
+
"paths": {
102
+
"~/*": ["src/*"]
103
+
}
94
104
}
95
105
```
96
106
@@ -107,6 +117,7 @@ import Module from '~/Module'
107
117
```
108
118
109
119
## Source Maps
120
+
110
121
Source maps are enabled by default and postfixed with `.map` in the `build` and `dist` folders. These files provide accurate source mappings which are helpful when debugging errors and looking at stack traces during runtime.
111
122
112
123
In order to tell Node to use these source maps, you would need to install `source-map-support`.
@@ -120,12 +131,71 @@ npm i -S source-map-support
120
131
```
121
132
122
133
Then, in `src/index.ts`, add:
134
+
123
135
```ts
124
136
import'source-map-support/register'
125
137
```
126
138
127
139
## Monorepo Support
140
+
128
141
To use `typescript-node-scripts` with a monorepo like lerna + yarn workspaces, you need to add `--monorepo` to the start and build scripts.
129
142
130
143
Then, you can use `lerna run <start|build> --stream` in your root `package.json`.
131
144
145
+
## Debugging
146
+
147
+
### Visual Studio Code
148
+
149
+
#### Webpack Build
150
+
151
+
TNS incrementally outputs a single bundle in `build/bundle.js` (via webpack) when running `yarn build`.
152
+
To debug the bundle, add the following into the `configurations` array of your `launch.json` file:
153
+
154
+
```json
155
+
{
156
+
"type": "node",
157
+
"request": "launch",
158
+
"name": "Debug Webpack Build (via Node)",
159
+
"protocol": "inspector",
160
+
"program": "${workspaceFolder}/build/bundle.js"
161
+
}
162
+
```
163
+
164
+
You can now set breakpoints and run the task in order to debug your build.
165
+
166
+
#### TypeScript Source via `ts-node`
167
+
168
+
_This method is **NOT** recommended due to ts-node being quite slow at running and compiling your source code._
169
+
170
+
First off, you would need to install `ts-node` and `tsconfig-paths`:
0 commit comments