Missing dependency during unit testing
Category
- [x] Question
- [ ] Typo
- [x] Bug
- [ ] Enhancement / Suggestion
- [ ] Additional article idea
Expected or Desired Behavior
When I was writing unit tests against the webpart class, I get an error that the @ms/sp-telemetry is missing.
Observed Behavior
While running gulp test I receive the following error:
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
Error: Cannot find module "@ms/sp-telemetry"
at /Users/<user>/nodejs/spfx/testing-wp/temp/tests.js:52957
Steps to Reproduce
describe('<HelloWorldWebPart />', () => {
it('Should open the webpart', () => {
const mockCtx = new MockWebPartContext();
const wp = mockCtx.initialize(new HelloWorldWebPart());
});
});
When I write this in a test I get the error. When I remove const wp = mockCtx.initialize(new HelloWorldWebPart());, all other tests keep working.
When you just do something like this const wp = new HelloWorldWebPart() you get the same error.
Yes, still the same missing dependency.
Also the same in the new update.
Yes, still the same missing dependency.
This is a known issue. We're working on a solution.
I have the same error on test running if I import in the code:
import { HttpClient } from "@microsoft/sp-http";
Is there a workaround for this issue?
We also have the same problem and need a workaround for this issue.
Have the same issue when running tests Module not found: Error: Can't resolve ms sp-telemetry
any help ?
Uncaught Error: Cannot find module "@ms/sp-telemetry" at webpackMissingModule
Upgraded to latest sharepoint yoeman generator, and still getting this issue. I have removed node_modules folder, tried npm install / npm install --save-dev. Tried gulp clean. Module still missing.
Is there any update on this issue? Has anyone got around this issue and have a workaround?
Edit [Add version details] microsoft/[email protected] npm 3.10.10 node v6.10.2
Update: Isolated my occurrence to "sp-pnp-js": "2.0.6". Will do an update to version 2.0.7 and get back with the results.
Update: Issue for me is resolved by update to sp-pnp-js 2.0.7
I have run the following command to see packages
λ npm -g list --depth=0
removed and installed again updated [email protected] and [email protected]
still having issues
Also having issues with this.
Hi All, after some debugging and following @buckyaustin update. I found that there was a duplicate @assets import within my WebPart, when I remove this the error "Module not found: Error: Can't resolve ms sp-telemetry" was gone and my unit tests started working again.
Not working me .. anu update
Same here. Any updates on this?
@iclanton Can you provide an update on this? Would be greatly appreciated :).
I checked and found that every method which is making a calll the http service needs to be stub and it worked for me
@deploymentvsureshk Could be so kind as to create an example (HelloWorld WebPart) to demonstrate it?
Further information that might help.
I have seen this occur on the following @ microsoft/sp-loader.SPComponentLoader.loadCss @ microsoft/sp-loader.SPComponentLoader.loadScript @ microsoft/sp-http.HttpClient sp-pnp-js.pnp.web.lists
Just using the import statement for these doesn't cause the problem, but using methods within them causes the problem to occur.
I'm assuming there is a common class/method that all of these use that is causing the problem.
You should stub responses from ajax or switch out a class that does the http call for another class that doesn't use http. In my build we switch classes so the http code doesn't get executed. Just by having the methods used in the code base is enough to cause the tests to fail even though they are not invoked in the tests. Commenting out the use of the methods allows gulp test to execute.
Hope this information helps.
Hey I am getting the same error as well. Version 1.2.0 of the SPFx. Seems that @ms/sp-telemetry package is included with almost all the SPFx libraries. When gulp test is run in the temp folder we get manifest and the @ms/sp-telemetry is hooked to almost every SPFx Library and Application including SPLoader, SPHttp, SPPageContext, SPComponentBase, SPWebPartBase, SPExtensionBase, WebPartWorkbench, SPLoader. However if we go to the SPFx node modules and reverse engeneer for a while we see that this is package is from internal Microsoft NPM server.
"description": "An internal package supporting the SharePoint Framework",
"devDependencies": {
"@ms/odsp-utilities-bundle": "~1.1.0",
"@ms/sp-build-internal-web": "~0.6.1",
"@ms/sp-telemetry": "~0.2.2",
"@types/chai": "3.4.34",
"@types/mocha": "2.2.38",
"@types/sinon": "1.16.34",
"@uifabric/styling": "0.15.2",
"chai": "~3.5.0",
"gulp": "~3.9.1",
"sinon": "~1.17.6"
}
Please remove that package from the loaderConfig so we can test or make it publicly available. Thanks!
This also affects "@microsoft/sp-dialog" where the internal "@ms/sp-telemetry": "~0.2.2" is in the dev dependencies, But is used extensively in the code.
The missing class is a class to do some logging.
IMHO, It should be moved to the dependencies (from dev) for the module and made public, or all references to the logger should be removed, or a stub alternate provided.
My versions are:
"@microsoft/decorators": "~1.3.0",
"@microsoft/sp-application-base": "1.3.0",
"@microsoft/sp-core-library": "~1.3.0",
"@microsoft/sp-dialog": "1.3.0",
"@microsoft/sp-http": "^1.2.0",
"@microsoft/sp-lodash-subset": "~1.3.0",
"@microsoft/sp-webpart-base": "~1.3.0",