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

Use ts-mocha to run tests #444

Merged
merged 14 commits into from
Mar 27, 2019
86 changes: 86 additions & 0 deletions packages/opencensus-core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/opencensus-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
"types": "build/src/index.d.ts",
"repository": "census-instrumentation/opencensus-node",
"scripts": {
"test": "nyc mocha build/test/**/*.js",
"test": "nyc ts-mocha -p ./tsconfig.json test/**/*.ts",
"codecov": "nyc report --reporter=json && codecov -f coverage/*.json",
"clean": "rimraf build/*",
"check": "gts check",
"compile": "tsc -p .",
"compile:release": "tsc -p tsconfig-release.json",
"fix": "gts fix",
"prepare": "npm run compile:release",
"pretest": "npm run compile",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should still keep this and add into unit test workflow. Something like below in .circleci/config.yml WDYT?

   - run:
        name: Compile code
        command: npm run compile

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like that config is for the entire repo. That would cause all of the other packages to run the compile step twice. Is that ok and/or should I change all of the other packages to use ts-mocha?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to change all packages to use ts-mocha. Also, does it make sense to remove dependencies on mocha and @types/mocha after this? @draffensperger any thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we can't remove the dependencies. The ts-mocha page says we need them: https://www.npmjs.com/package/ts-mocha

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok SG.

"posttest": "npm run check"
},
"keywords": [
Expand Down Expand Up @@ -54,6 +53,7 @@
"intercept-stdout": "^0.1.2",
"mocha": "^6.0.0",
"nyc": "13.3.0",
"ts-mocha": "^6.0.0",
"ts-node": "^8.0.0",
"typescript": "~2.9.0"
},
Expand Down
13 changes: 10 additions & 3 deletions packages/opencensus-core/src/common/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ type Package = {
};

// Load the package details. Note that the `require` is performed at runtime,
// which means the source files will be in the `/build` directory, so the
// package path is relative to that location.
const pjson: Package = require('../../../package.json');
// which means package.json will be relative to the location of this file.
// If this file has been compiled, it will be in the `/build` directory, so the
// package path is relative to that location. Otherwise, it will be relative
// to the original .ts file.
let pjson: Package;
try {
pjson = require('../../../package.json');
} catch {
pjson = require('../../package.json');
}

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