Skip to content
This repository has been archived by the owner on Jun 21, 2020. It is now read-only.

Commit

Permalink
Adds Karma runner to debug tests.
Browse files Browse the repository at this point in the history
Refs #1.

This includes a `test:debug` script to execute Karma. Karma's config uses the existing `tsconfig.spec.json` so test builds should be consistent between test and debug, though I suspect Karma adds its own options for sourcemapping.

I had a lot of fun trying to get sourcemaps to work. The compiled JavaScript would be wrapped in coverage instrumentation, so the sourcemap comment was not at the end of the file, and thus would not be picked up by the browser. Eventually, I found the option to disable coverage which removed the instrumentation and Chrome was able to pick up the sourcemap. This does mean that coverage is very likely broken, but I'm not that concerned about it at the moment.

I also discovered that Lerna's `--scope` command was not actually working. I would run `npm run lerna run foo --scope packages/bar/`, however `--scope` is actually an NPM argument, so NPM accepts it and does not pass it to Lerna. Since the repo is currently just one package, the lack of a scope would run on all packages, which is just that one so I had not noticed. Running `npm run -- foo-script` properly escapes arguments after the `--`. At this point I also discovered that the `--scope` flag expects a package name, not a path, so the *correct* way to run a command through Lerna is actually:

```shell
npm run -- lerna run foo --scope bar
```

Updated the documentation to reflect this. If `foo` expects arguments, though should also follow a second `--`, for example:

```shell
npm run -- lerna run foo --scope bar -- --baz hello/world.txt
# Runs `npm run foo --baz hello/world.txt` in package `bar`
```
  • Loading branch information
dgp1130 committed May 3, 2020
1 parent e01d29a commit d62a26b
Show file tree
Hide file tree
Showing 4 changed files with 2,973 additions and 106 deletions.
23 changes: 16 additions & 7 deletions packages/bxpb-runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,31 @@ Client classes are typically generated by `bxpb-protoc-plugin` and not hand-writ
To build just this package, run from the repository root:

```shell
npm run lerna run build --scope packages/bxpb-runtime/ --include-dependencies
npm run -- lerna run build --scope bxpb-runtime --include-dependencies
```

Output files are stored in the `dist/` directory.

### Test

Unit tests are run from the repository root:
Build and run unit tests with this command (run from the repository root):

```shell
npm run lerna run test --scope packages/bxpb-runtime/
npm run -- lerna run build --scope bxpb-runtime --include-dependencies &&
npm run -- lerna run test --scope bxpb-runtime
```

You should probably build and test in the same command:
You can debug tests by running:

```shell
npm run lerna run build --scope packages/bxpb-runtime/ --include-dependencies &&
npm run lerna run test --scope packages/bxpb-runtime/
```
npm run -- lerna run build --scope bxpb-runtime --include-dependencies &&
npm run -- lerna run test:debug --scope bxpb-runtime
```

This will start Karma on port 9876, open a browser to http://localhost:9876/debug.html to start
debugging. Sourcemaps should work out of the box and are available under the `/base` directory in
DevTools.

Karma will live reload and incorpate any changes from the package without requiring a restart.
However this only works for changes within `bxpb-runtime`. If any dependent packages are modified,
this will likely require a full rebuild.
23 changes: 23 additions & 0 deletions packages/bxpb-runtime/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = function (config) {
config.set({
basePath: '',
frameworks: [ 'jasmine', 'karma-typescript' ],
files: [
'src/**/*.ts',
],
preprocessors: {
'**/*.ts': 'karma-typescript',
},
karmaTypescriptConfig: {
tsconfig: './tsconfig.spec.json',

// Disable coverage, or else it wraps source files inline and blocks the sourcemap
// comment from being at the end of the file, thus the browser cannot parse it
// correctly. By disabling coverage, source maps work as expected.
coverageOptions: {
instrumentation: false,
},
},
reporters: [ 'karma-typescript', 'kjhtml' ],
});
};
Loading

0 comments on commit d62a26b

Please sign in to comment.