Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 4b7d14c

Browse files
Ken Ashcraftmayurkale22
Ken Ashcraft
authored andcommitted
Use ts-mocha to run tests (#444)
* Use ts-mocha to run tests * Add compile step to CI * Update all packages to use ts-mocha * Fix typo around pjsonVersion * Delete spurious blank line * Get .ts coverage for all packages * Undo changes to opencensus-nodejs/package.json. It needs to be compiled to .js to get the tests to pass. * Undo ts-mocha for redis package * Don't use ts-mocha for ocagent * Revert package-lock.json and ocagent.ts since we aren't going to change package.json as part of this PR. * Remove unnecessary nyc block * Undo changes to package-lock.json * Handle templatesDir
1 parent c5a7d07 commit 4b7d14c

File tree

46 files changed

+1877
-109
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1877
-109
lines changed

.circleci/config.yml

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ unit_tests: &unit_tests
1414
- run:
1515
name: Install modules and dependencies.
1616
command: npm install
17+
- run:
18+
name: Ensure code compiles to JS.
19+
command: npm run compile
1720
- run:
1821
name: Run unit tests.
1922
command: npm run test

packages/opencensus-core/package-lock.json

+86
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/opencensus-core/package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
"types": "build/src/index.d.ts",
77
"repository": "census-instrumentation/opencensus-node",
88
"scripts": {
9-
"test": "nyc mocha build/test/**/*.js",
9+
"test": "nyc ts-mocha -p ./tsconfig.json test/**/*.ts",
1010
"codecov": "nyc report --reporter=json && codecov -f coverage/*.json",
1111
"clean": "rimraf build/*",
1212
"check": "gts check",
1313
"compile": "tsc -p .",
1414
"compile:release": "tsc -p tsconfig-release.json",
1515
"fix": "gts fix",
1616
"prepare": "npm run compile:release",
17-
"pretest": "npm run compile",
1817
"posttest": "npm run check"
1918
},
2019
"keywords": [
@@ -38,6 +37,16 @@
3837
"LICENSE",
3938
"README.md"
4039
],
40+
"nyc": {
41+
"extension": [
42+
".ts",
43+
".tsx"
44+
],
45+
"exclude": [
46+
"**/*.d.ts"
47+
],
48+
"all": true
49+
},
4150
"publishConfig": {
4251
"access": "public"
4352
},
@@ -54,6 +63,7 @@
5463
"intercept-stdout": "^0.1.2",
5564
"mocha": "^6.0.0",
5665
"nyc": "13.3.0",
66+
"ts-mocha": "^6.0.0",
5767
"ts-node": "^8.0.0",
5868
"typescript": "~2.9.0"
5969
},

packages/opencensus-core/src/common/version.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,16 @@ type Package = {
2020
};
2121

2222
// Load the package details. Note that the `require` is performed at runtime,
23-
// which means the source files will be in the `/build` directory, so the
24-
// package path is relative to that location.
25-
const pjson: Package = require('../../../package.json');
23+
// which means package.json will be relative to the location of this file.
24+
// If this file has been compiled, it will be in the `/build` directory, so the
25+
// package path is relative to that location. Otherwise, it will be relative
26+
// to the original .ts file.
27+
let pjson: Package;
28+
try {
29+
pjson = require('../../../package.json');
30+
} catch {
31+
pjson = require('../../package.json');
32+
}
2633

2734
// Export the core package version
2835
export const version: string = pjson.version;

packages/opencensus-exporter-instana/package-lock.json

+86
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/opencensus-exporter-instana/package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
"types": "build/src/index.d.ts",
77
"repository": "census-instrumentation/opencensus-node",
88
"scripts": {
9-
"test": "nyc mocha build/test/**/*.js",
9+
"test": "nyc ts-mocha -p ./tsconfig.json test/**/*.ts",
1010
"codecov": "nyc report --reporter=json && codecov -f coverage/*.json",
1111
"clean": "rimraf build/*",
1212
"check": "gts check",
1313
"compile": "tsc -p .",
1414
"fix": "gts fix",
1515
"prepare": "npm run compile",
16-
"pretest": "npm run compile",
1716
"posttest": "npm run check"
1817
},
1918
"keywords": [
@@ -36,6 +35,16 @@
3635
"LICENSE",
3736
"README.md"
3837
],
38+
"nyc": {
39+
"extension": [
40+
".ts",
41+
".tsx"
42+
],
43+
"exclude": [
44+
"**/*.d.ts"
45+
],
46+
"all": true
47+
},
3948
"publishConfig": {
4049
"access": "public"
4150
},
@@ -48,6 +57,7 @@
4857
"mocha": "^6.0.0",
4958
"nock": "^10.0.0",
5059
"nyc": "13.3.0",
60+
"ts-mocha": "^6.0.0",
5161
"ts-node": "^8.0.0",
5262
"typescript": "~3.2.0"
5363
},

0 commit comments

Comments
 (0)