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

Commit

Permalink
Adds generated test data.
Browse files Browse the repository at this point in the history
Refs #1.

This introduces `greeter.proto` which includes a simple service for testing purposes. It generates TypeScript declarations and puts them in `generated/`, using TypeScript's `paths` feature to map imports. Karma also needs to map the JavaScript in a similar fashion to resolve itself.

I also refactored the way the `tsconfig.json` files worked to better support this. Now there are three config files which are all a bit different:
* `tsconfig.json` is meant for the editor and contains all TypeScript files (including generated). This allows the IDE to resolve all imports in all files so there are no awkward red squigglies that don't go away.
* `tsconfig.lib.json` is for actually running the compilation. It simply excludes test files, so as not to accidentally use them in a production build.
* `tsconfig.spec.json` is for running tests. It forces a different output directory and format to be compatible with Karma.

One downside of this strategy is that the editor belives all imports are available from all locations which isn't strictly true. For example, `service.ts` should **not** reference Jasmine's `describe()` function, but the editor will not complain about this. In TypeScript 3.9, solution style configs allow for more flexibility in the editor and should be able to better support this format. Filed #3 to look into this when TS3.9 launches.
  • Loading branch information
dgp1130 committed May 8, 2020
1 parent a30e0dc commit 9edc1bc
Show file tree
Hide file tree
Showing 8 changed files with 605 additions and 71 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# BXPB
test-out/
generated/

# Logs
logs
Expand Down
10 changes: 10 additions & 0 deletions packages/bxpb-runtime/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ module.exports = function (config) {
karmaTypescriptConfig: {
tsconfig: './tsconfig.spec.json',

// Need to manually resolve paths to JavaScript modules.
// See: https://stackoverflow.com/a/53605376
bundlerOptions: {
resolve: {
alias: {
'generated/test_data/greeter_pb': 'generated/test_data/greeter_pb.js',
},
},
},

// 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.
Expand Down
Loading

0 comments on commit 9edc1bc

Please sign in to comment.