Forum Discussion
Sharepoint Framework with custom npm package and testing
Background Info
I'm having trouble testing my solution once I've included a custom npm package (through VSTS). I've setup my tests by following Elio Struyf's https://www.eliostruyf.com/writing-unit-test-for-your-sharepoint-framework-components/ and created a npm package following another https://codeburst.io/https-chidume-nnamdi-com-npm-module-in-typescript-12b3b22f0724 I found on the subject. I then followed VSTS guide for setting up the package for distribution and seemingly everything works.
Trouble
Once I added the package and ran gulp test I got the following error from karma/PhantomJS:
14 02 2018 11:55:19.868:DEBUG [phantomjs.launcher]: Error: Cannot find module "oz-date-utils" 14 02 2018 11:55:19.868:DEBUG [phantomjs.launcher]: http://localhost:9876/base/temp/tests.js?d8f3aa9c7d469d8d14c04541e9480ad6098bbb15:43884 in webpackMissingModule http://localhost:9876/base/temp/tests.js?d8f3aa9c7d469d8d14c04541e9480ad6098bbb15:43884 http://localhost:9876/base/temp/tests.js?d8f3aa9c7d469d8d14c04541e9480ad6098bbb15:20 in __webpack_require__ http://localhost:9876/base/temp/tests.js?d8f3aa9c7d469d8d14c04541e9480ad6098bbb15:43819 http://localhost:9876/base/temp/tests.js?d8f3aa9c7d469d8d14c04541e9480ad6098bbb15:20 in __webpack_require__ http://localhost:9876/base/temp/tests.js?d8f3aa9c7d469d8d14c04541e9480ad6098bbb15:19121 in webpackContext :0 in forEach http://localhost:9876/base/temp/tests.js?d8f3aa9c7d469d8d14c04541e9480ad6098bbb15:19109 http://localhost:9876/base/temp/tests.js?d8f3aa9c7d469d8d14c04541e9480ad6098bbb15:20 in __webpack_require__ http://localhost:9876/base/temp/tests.js?d8f3aa9c7d469d8d14c04541e9480ad6098bbb15:63 PhantomJS 2.1.1 (Windows 8.0.0) ERROR Error: Cannot find module "oz-date-utils" at C:/Users/ketill/Vinna/frameWORK/ozGanttChartResourceManagement/temp/tests.js:43884 PhantomJS 2.1.1 (Windows 8.0.0) ERROR Error: Cannot find module "oz-date-utils" at C:/Users/ketill/Vinna/frameWORK/ozGanttChartResourceManagement/temp/tests.js:43884
Frankly I don't even know where to begin as I've never used Karma or Phantom before. I've tried going through the npm demo again and comparing my package to others and noticed no apparent discrepancy.
All help greatly appreciated, I'll gladly provide sources for anything that might help but I decided not to overcrowd this original post :)
1 Reply
- Ketill Antoníus ÁgústssonCopper ContributorTurns out it was quite basic, I had my main index.js file according to the npm package's package.json set wrong. That wasn't apparent because TypeScript picked up the original index.ts in the root. PhantomJS / Karma then didn't understand that file and couldn't find the correct index.js file.