mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-20 06:07:57 +00:00
Use tsconfig-paths for easier access to the source
Currently, tests only can import source code modules through relative paths `../../`. This makes it very difficult to refactor and organize tests in folders as the paths change. [tsconfig-paths](https://www.npmjs.com/package/tsconfig-paths) allows to reference the source through an alias defined in the "paths" section of tsconfig.json
This commit is contained in:
parent
1439ee30f2
commit
71eaa3327e
31
package-lock.json
generated
31
package-lock.json
generated
@ -9760,6 +9760,12 @@
|
||||
"ansi-regex": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"strip-bom": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz",
|
||||
"integrity": "sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==",
|
||||
"dev": true
|
||||
},
|
||||
"strip-final-newline": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz",
|
||||
@ -10446,6 +10452,31 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"tsconfig-paths": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-4.1.0.tgz",
|
||||
"integrity": "sha512-AHx4Euop/dXFC+Vx589alFba8QItjF+8hf8LtmuiCwHyI4rHXQtOOENaM8kvYf5fR0dRChy3wzWIZ9WbB7FWow==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"json5": "^2.2.1",
|
||||
"minimist": "^1.2.6",
|
||||
"strip-bom": "^3.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"json5": {
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/json5/-/json5-2.2.1.tgz",
|
||||
"integrity": "sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA==",
|
||||
"dev": true
|
||||
},
|
||||
"minimist": {
|
||||
"version": "1.2.6",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz",
|
||||
"integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"tslib": {
|
||||
"version": "1.9.3",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz",
|
||||
|
@ -119,6 +119,7 @@
|
||||
"tmp": "^0.1.0",
|
||||
"ts-loader": "^7.0.5",
|
||||
"ts-node": "^8.10.2",
|
||||
"tsconfig-paths": "^4.1.0",
|
||||
"typed-error": "^3.2.1",
|
||||
"typescript": "^4.2.4",
|
||||
"webpack": "^4.44.1",
|
||||
|
@ -5,6 +5,7 @@ module.exports = {
|
||||
require: [
|
||||
// Files to execute before running suites
|
||||
'ts-node/register/transpile-only',
|
||||
'tsconfig-paths/register',
|
||||
'test/config/fixtures.ts',
|
||||
],
|
||||
spec: ['test/**/*.spec.ts'],
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { expect } from 'chai';
|
||||
import constants = require('../src/lib/constants');
|
||||
import * as constants from '~/src-lib/constants';
|
||||
|
||||
describe('constants', function () {
|
||||
it('has the correct configJsonPathOnHost', () =>
|
||||
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": "./",
|
||||
"target": "ES2019",
|
||||
"module": "commonjs",
|
||||
"strict": true,
|
||||
@ -11,7 +12,13 @@
|
||||
"skipLibCheck": true,
|
||||
"lib": ["es2019"],
|
||||
"resolveJsonModule": true,
|
||||
"allowJs": true
|
||||
"allowJs": true,
|
||||
"paths": {
|
||||
"~/src/*": ["src/*"],
|
||||
"~/lib/*": ["src/lib/*"],
|
||||
"~/test-lib/*": ["test/lib/*"],
|
||||
"~/test-data/*": ["test/data/*"]
|
||||
}
|
||||
},
|
||||
"include": ["src/**/*", "test/**/*", "typings/**/*.d.ts"]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user