1

When setting up schematics in a library you end up with a structure like so:

library
-schematics
--update
---index.spec.ts
-src
--test.ts

How would I setup the index.spec.ts to run with the library tests when the nested test.ts searches for tests at or below itself:

const context = require.context('./', true, /\.spec\.ts$/);

and looking up a folder crashes.

Unfortunately, the sparse schematics documentation skips testing (among virtually everything else that might be useful). https://angular.io/guide/schematics-for-libraries

Anthony
  • 7,638
  • 3
  • 38
  • 71

1 Answers1

0

So, after a good week of working on this exact problem, i was able finally get my schematics unit test situation sorted. The quick answer to your question is that you actually don't have the project's usual testing mechanism run the schematics tests. You have to run them separately. Since the rest of your library probably uses some kind of browser to execute your test cases (e.g. via Karma), that setup isn't really suitable for running schematic tests, since schematics aren't run by a browser. They're command line functions. So you have to segment your testing. I put in a dedicated schm:test npm script that uses jasmine to run the schematics tests on their own.

"schm:test": "npm run schm:build && jasmine dist/schematics/**/*.spec.js",
mfaith
  • 115
  • 3
  • 11