sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

Missing dependency during unit testing

Open estruyf opened this issue 9 years ago • 45 comments

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.

estruyf avatar Mar 31 '17 10:03 estruyf

Yes, still the same missing dependency.

estruyf avatar Jun 06 '17 08:06 estruyf

Also the same in the new update.

estruyf avatar Jun 07 '17 07:06 estruyf

Yes, still the same missing dependency.

chan4lk avatar Jun 11 '17 17:06 chan4lk

This is a known issue. We're working on a solution.

iclanton avatar Jun 15 '17 18:06 iclanton

I have the same error on test running if I import in the code: import { HttpClient } from "@microsoft/sp-http";

Hennadiy avatar Jul 04 '17 11:07 Hennadiy

Is there a workaround for this issue?

kbrimington avatar Jul 31 '17 18:07 kbrimington

We also have the same problem and need a workaround for this issue.

bastianjohn avatar Aug 15 '17 06:08 bastianjohn

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

ghost avatar Sep 05 '17 13:09 ghost

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

AustinBreslinDev avatar Sep 05 '17 13:09 AustinBreslinDev

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

ghost avatar Sep 05 '17 14:09 ghost

Also having issues with this.

jacobhummel avatar Sep 05 '17 21:09 jacobhummel

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.

ghost avatar Sep 06 '17 15:09 ghost

Not working me .. anu update

deploymentvsureshk avatar Sep 09 '17 04:09 deploymentvsureshk

Same here. Any updates on this?

FranckyC avatar Sep 29 '17 01:09 FranckyC

@iclanton Can you provide an update on this? Would be greatly appreciated :).

ghost avatar Oct 04 '17 10:10 ghost

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 avatar Oct 04 '17 13:10 deploymentvsureshk

@deploymentvsureshk Could be so kind as to create an example (HelloWorld WebPart) to demonstrate it?

ghost avatar Oct 05 '17 12:10 ghost

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.

AustinBreslinDev avatar Oct 12 '17 13:10 AustinBreslinDev

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!

VelinGeorgiev avatar Oct 13 '17 08:10 VelinGeorgiev

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",

YonasJ avatar Oct 19 '17 13:10 YonasJ