Skip to content

Commit 76a7f56

Browse files
committed
fix: apply source-maps to test errors
When we got rid of ts-node in #602, we also unintentionally dropped the code modifying error stack traces to point to original TypeScript sources instead of the transpiled JavaScript output. As a result, assertion failures contained stack traces pointing to code that we are not familiar with, which made troubleshooing difficult. This commits add source-map-support as a global dev-dependency plus a dev-dependency of example repositories that must work outside of our monorepo too. The single shared `mocha.opts` was split into two different options files: - `mocha.ts.opts` which registers source-map support - `mocha.js.opts` with no support for source maps
1 parent 8f3d135 commit 76a7f56

File tree

18 files changed

+42
-33
lines changed

18 files changed

+42
-33
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"node": ">=6"
1010
},
1111
"license": "MIT",
12-
"dependencies": {},
1312
"devDependencies": {
1413
"@commitlint/cli": "^6.0.2",
1514
"@commitlint/config-conventional": "^6.0.2",
@@ -19,7 +18,8 @@
1918
"coveralls": "^3.0.0",
2019
"cz-conventional-changelog": "^2.1.0",
2120
"lerna": "^2.5.1",
22-
"mocha": "^5.0.0"
21+
"mocha": "^5.0.0",
22+
"source-map-support": "^0.5.2"
2323
},
2424
"scripts": {
2525
"bootstrap": "npm i && lerna bootstrap",
@@ -41,7 +41,7 @@
4141
"build:full": "npm run clean:full && npm run bootstrap && npm run build && npm run mocha && npm run lint",
4242
"pretest": "npm run clean && npm run build:current",
4343
"test": "node packages/build/bin/run-nyc npm run mocha",
44-
"mocha": "node packages/build/bin/select-dist mocha --opts packages/build/mocha.opts \"packages/*/DIST/test/**/*.js\" \"packages/cli/test\"",
44+
"mocha": "node packages/build/bin/select-dist mocha --opts packages/build/mocha.ts.opts \"packages/*/DIST/test/**/*.js\" \"packages/cli/test\"",
4545
"posttest": "npm run lint"
4646
},
4747
"config": {

packages/authentication/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
"node": ">=6"
77
},
88
"scripts": {
9-
"acceptance": "lb-dist mocha --opts node_modules/@loopback/build/mocha.opts 'DIST/test/acceptance/**/*.js'",
9+
"acceptance": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/acceptance/**/*.js'",
1010
"build": "npm run build:dist && npm run build:dist6",
1111
"build:current": "lb-tsc",
1212
"build:dist": "lb-tsc es2017",
1313
"build:dist6": "lb-tsc es2015",
1414
"build:apidocs": "lb-apidocs",
1515
"clean": "lb-clean loopback-authentication*.tgz dist dist6 package api-docs",
16-
"integration": "lb-dist mocha --opts node_modules/@loopback/build/mocha.opts 'DIST/test/integration/**/*.js'",
16+
"integration": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/integration/**/*.js'",
1717
"prepare": "npm run build && npm run build:apidocs",
1818
"pretest": "npm run build:current",
19-
"test": "lb-dist mocha --opts node_modules/@loopback/build/mocha.opts 'DIST/test/unit/**/*.js' 'DIST/test/integration/**/*.js' 'DIST/test/acceptance/**/*.js'",
20-
"unit": "lb-dist mocha --opts node_modules/@loopback/build/mocha.opts 'DIST/test/unit/**/*.js'",
19+
"test": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/unit/**/*.js' 'DIST/test/integration/**/*.js' 'DIST/test/acceptance/**/*.js'",
20+
"unit": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/unit/**/*.js'",
2121
"verify": "npm pack && tar xf loopback-authentication*.tgz && tree package && npm run clean"
2222
},
2323
"author": "IBM",

packages/build/mocha.ts.opts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--recursive
2+
--exit
3+
--reporter dot
4+
--require source-map-support/register

packages/build/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"prettier:check": "npm run prettier:cli -- -l",
4141
"prettier:fix": "npm run prettier:cli -- --write",
4242
"test": "npm run mocha",
43-
"mocha": "node bin/select-dist mocha --timeout 30000 --opts mocha.opts \"test/integration/*.js\"",
43+
"mocha": "node bin/select-dist mocha --opts mocha.js.opts --timeout 30000 \"test/integration/*.js\"",
4444
"posttest": "npm run lint"
4545
},
4646
"devDependencies": {

packages/cli/generators/project/templates/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272
<% if (project.mocha) { -%>
7373
"@loopback/testlab": ">=4.0.0-alpha.13",
7474
"@types/mocha": "^2.2.43",
75-
"mocha": "^4.0.1"
75+
"mocha": "^4.0.1",
76+
"source-map-support": "^0.5.2"
7677
<% } else { -%>
7778
"@loopback/testlab": ">=4.0.0-alpha.13"
7879
<% } -%>

packages/cli/generators/project/templates/package.plain.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<% if (project.mocha) { -%>
7878
"@types/mocha": "^2.2.43",
7979
"mocha": "^4.0.1",
80+
"source-map-support": "^0.5.2",
8081
<% } -%>
8182
"typescript": "^2.5.3"
8283
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
--recursive
2+
--require source-map-support/register

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
},
5555
"scripts": {
5656
"prepublishOnly": "nsp check",
57-
"test": "mocha test/**/*.js"
57+
"test": "mocha --opts node_modules/@loopback/build/mocha.js.opts test/**/*.js"
5858
},
5959
"repository": {
6060
"type": "git",

packages/context/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"node": ">=6"
77
},
88
"scripts": {
9-
"acceptance": "lb-dist mocha --opts node_modules/@loopback/build/mocha.opts 'DIST/test/acceptance/**/*.js'",
9+
"acceptance": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/acceptance/**/*.js'",
1010
"build": "npm run build:dist && npm run build:dist6",
1111
"build:current": "lb-tsc",
1212
"build:dist": "lb-tsc es2017",
@@ -15,8 +15,8 @@
1515
"clean": "lb-clean loopback-context*.tgz dist dist6 package api-docs",
1616
"prepare": "npm run build && npm run build:apidocs",
1717
"pretest": "npm run build:current",
18-
"test": "lb-dist mocha --opts node_modules/@loopback/build/mocha.opts 'DIST/test/unit/**/*.js' 'DIST/test/acceptance/**/*.js'",
19-
"unit": "lb-dist mocha --opts node_modules/@loopback/build/mocha.opts 'DIST/test/unit/**/*.js'",
18+
"test": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/unit/**/*.js' 'DIST/test/acceptance/**/*.js'",
19+
"unit": "lb-dist mocha --opts node_modules/@loopback/build/mocha.ts.opts 'DIST/test/unit/**/*.js'",
2020
"verify": "npm pack && tar xf loopback-context*.tgz && tree package && npm run clean"
2121
},
2222
"author": "IBM",

0 commit comments

Comments
 (0)