Reputation: 726
My project is developed with TypeScript for frontend.
The project file structure is something like this:
index.ts
mymodule.ts
mymodule_test.ts
As Hammer.js uses the global window
and document
object internally, I added some tricky code before the import statement for test only purposes.
mymodule.ts
1: import * as jsdom from 'jsdom';
2: if (typeof window === 'undefined') {
3: let testDom: HTMLDocument = jsdom.jsdom('', undefined);
4: (<any> global).window = testDom.defaultView;
5: (<any> global).document = testDom;
6: }
7: import * as Hammer from 'hammerjs';
...
Now test runs successfuly. But build fails and spits out the following error:
Running "shell:minify" (shell) task
/home/yunbo/Workspace/jobkey/frontend/node_modules/jsmin/jsmin.js:231
throw 'Error: unterminated string literal: ' + a;
^
Error: unterminated string literal:
I searched for a while and found some Q&As about such an error.
To avoid that error, I should modify the JSDOM's internal code or remove 1 - 6 lines in mymodule.ts
. But both are not affordable.
mymodule.ts
, I cannot run the tests.How can I solve this issue? Should I use another JavaScript minifier? Or should not test mymodule.js
that includes Hammer.js import statement?
Upvotes: 3
Views: 214