New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing dependency during unit testing #526

Closed
estruyf opened this Issue Mar 31, 2017 · 41 comments

Comments

Projects
None yet
@estruyf
Contributor

estruyf commented Mar 31, 2017

Category

  • Question
  • Typo
  • 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.

@nickpape-msft

This comment has been minimized.

Contributor

nickpape-msft commented Jun 5, 2017

@estruyf are you still seeing this issue?

@estruyf

This comment has been minimized.

Contributor

estruyf commented Jun 6, 2017

Yes, still the same missing dependency.

@estruyf

This comment has been minimized.

Contributor

estruyf commented Jun 7, 2017

Also the same in the new update.

@chan4lk

This comment has been minimized.

chan4lk commented Jun 11, 2017

Yes, still the same missing dependency.

@iclanton

This comment has been minimized.

Contributor

iclanton commented Jun 15, 2017

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

@Hennadiy

This comment has been minimized.

Hennadiy commented Jul 4, 2017

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

@kbrimington

This comment has been minimized.

kbrimington commented Jul 31, 2017

Is there a workaround for this issue?

@bastianjohn

This comment has been minimized.

bastianjohn commented Aug 15, 2017

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

@tonywatters

This comment has been minimized.

tonywatters commented Sep 5, 2017

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

@AustinBreslinDev

This comment has been minimized.

AustinBreslinDev commented Sep 5, 2017

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/generator-sharepoint@1.2.0
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

@tonywatters

This comment has been minimized.

tonywatters commented Sep 5, 2017

I have run the following command to see packages
λ npm -g list --depth=0
removed and installed again updated phantomjs@2.1.7 and windows-build-tools@1.3.2
still having issues

@jacobhummel

This comment has been minimized.

jacobhummel commented Sep 5, 2017

Also having issues with this.

@tonywatters

This comment has been minimized.

tonywatters commented Sep 6, 2017

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.

@deploymentvsureshk

This comment has been minimized.

deploymentvsureshk commented Sep 9, 2017

Not working me .. anu update

@FranckyC

This comment has been minimized.

Contributor

FranckyC commented Sep 29, 2017

Same here. Any updates on this?

@michel-weber michel-weber referenced this issue Oct 4, 2017

Closed

How to unit test webparts? #243

2 of 5 tasks complete
@michel-weber

This comment has been minimized.

michel-weber commented Oct 4, 2017

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

@deploymentvsureshk

This comment has been minimized.

deploymentvsureshk commented Oct 4, 2017

I checked and found that every method which is making a calll the http service needs to be stub
and it worked for me

@michel-weber

This comment has been minimized.

michel-weber commented Oct 5, 2017

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

@AustinBreslinDev

This comment has been minimized.

AustinBreslinDev commented Oct 12, 2017

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.

@VelinGeorgiev

This comment has been minimized.

Contributor

VelinGeorgiev commented Oct 13, 2017

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!

@YonasJ

This comment has been minimized.

YonasJ commented Oct 19, 2017

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

This comment has been minimized.

Contributor

VelinGeorgiev commented Oct 19, 2017

Another observation is that if you try for some reason to create/test new instance of class that uses SPComponentLoader within .test.ts file then it will throw the @ms/sp-telemetry error and fail all tests. By removing such classes and replacing with mock-ed classes that do now have the reference to SPComponentLoader might partially solve the issue.

@YonasJ

This comment has been minimized.

YonasJ commented Nov 6, 2017

I also get this error if I do this import:

import { SPHttpClient, SPHttpClientResponse } from '@microsoft/sp-http';

@ymihir

This comment has been minimized.

ymihir commented Nov 10, 2017

@YonasJ
I also faced same issue. But what i am having in my .ts file is

import SPHttpClient from '@microsoft/sp-http/lib/spHttpClient/SPHttpClient';
import SPHttpClientResponse from '@microsoft/sp-http/lib/spHttpClient/SPHttpClientResponse';

Since I am importing spHttpClient twice even though for different modules, it is giving error. If I change to import {SPHttpClient,SPHttpClientResponse} from '@microsoft/sp-http'; then it started working.
Hope this is helpful.

@PavelAl

This comment has been minimized.

PavelAl commented Nov 20, 2017

@ymihir solution worked for me as well.

@smithywick

This comment has been minimized.

smithywick commented Feb 27, 2018

With 1.3 this issue prevents testing of spHttpClient.

@tracy-zaact

This comment has been minimized.

tracy-zaact commented Mar 1, 2018

@VesaJuvonen - I see this is among the 6 issues still marked as 'status:fixed-next-drop'. Can someone tell me what that means from an ETA standpoint?

@AustinBreslinDev

This comment has been minimized.

AustinBreslinDev commented Mar 1, 2018

I can reproduce issue in spfx 1.4.0.

@lahuey

This comment has been minimized.

Collaborator

lahuey commented Mar 19, 2018

Hi,
Thank you for the feedback. Please add a feature request on UserVoice and depending on community interest we may or may not be able to make the fix.

@lahuey lahuey closed this Mar 19, 2018

@tracy-zaact

This comment has been minimized.

tracy-zaact commented Mar 23, 2018

@lahuey - Please correct me if I'm mistaken, but I don't think this is a feature request - it's a bug.

@michel-weber

This comment has been minimized.

michel-weber commented Mar 23, 2018

Is this fixed in 1.4.1?

@jacobhummel

This comment has been minimized.

jacobhummel commented Mar 23, 2018

@michel-weber We're still experiencing this issue in 1.4.1.

I saw the tag status:fixed-next-drop so I was under the impression that a fix would be rolled out soon. Is that not the case?

If this has been de-prioritized, does anyone know of any docs/blogs explaining how to work around this? This issue is blocking my team from doing any testing on web parts which include REST calls (all of our components do). Thanks for any info.

@michel-weber

This comment has been minimized.

michel-weber commented Mar 26, 2018

That was also my understanding. But the tag was added on the 28th of October 2017 - and since then 1.4.0 and 1.4.1 have been released. So I think this issue should be reopened.

@VesaJuvonen Can you look into this? Will this fix be released with the next version (> 1.4.1)?

@VelinGeorgiev

This comment has been minimized.

Contributor

VelinGeorgiev commented Mar 26, 2018

I think @lahuey is silently saying "Deal with it" :) . It has always been convenient to turn bug into a feature :) . Considering the fact that the testing scaffold templates are not in the latest framework anymore and the last comment from @patmill here #1335. I am not sure if we should still rely on the testing framework that comes with the frameworks anymore.

@piero-b

This comment has been minimized.

piero-b commented Apr 26, 2018

I have added a UserVoice to prioritise getting this fixed. Please up-vote it if you are interested as well.

@kezack

This comment has been minimized.

kezack commented Jun 27, 2018

I have the same problem with import { GraphHttpClient, HttpClientResponse} from '@microsoft/sp-http';

Error: Cannot find module "@ ms/sp-telemetry"

have you resolve this problem ?

@ericchin79

This comment has been minimized.

ericchin79 commented Jul 6, 2018

We are running into the same issue here

Cannot find module '@ms/sp-telemetry' from 'DigestCache.js'
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:179:17)
at Object. (node_modules/@microsoft/sp-http/lib/spHttpClient/DigestCache.js:3:22)

@deploymentvsureshk

This comment has been minimized.

deploymentvsureshk commented Jul 7, 2018

@adambarrettsmith

This comment has been minimized.

adambarrettsmith commented Aug 9, 2018

I'm running into a similar issue:

Cannot find module "@ms/sp-client-shared" which is being referenced under "..\node_modules\@Microsoft\sp-http\lib\oauthTokenProvider\OAuthTokenProvider.js"

@samyaktelsang

This comment has been minimized.

samyaktelsang commented Sep 17, 2018

Hey @adambarrettsmith . I'm running into a similar issue. Wondering if you could update this thread if you found a workaround. Thanks!

@grantbowering

This comment has been minimized.

grantbowering commented Nov 7, 2018

For the record:
I was experiencing this on 1.4.1, and ultimately ended up upgrading to 1.6.0-plusbeta which seems to have eliminated the problem.
(Recommendation: use office365-cli to retrieve steps for doing this upgrade, as there are a bunch of minor manual config changes it reports)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment