Comments (26)
I had the same problem, not with pact, but Ionic + Angular + Karma. The problem for me was caused by Webstorm sticking a bad import in one of my spec files:
import { describe } from "selenium-webdriver/testing";
Removed it and all got back to normal
from pact-js.
Hey @mefellows ,
Thanks, I will give it a go and let you know soon.
from pact-js.
Hi @NomiJ, I'm not familiar with Angular2 testing practices, but based on the log file you've provided it seems to use Karma under the hood. Have you looked at the karma examples for any hints?
In any case, child_process
is only available in a proper Node process, not any JS execution environment (such as a browser). You will need to start the mock service independently of your test suite for this to work. Typically, this is orchestrated via bash/grunt/gulp/.
If you could provide a working example to repro that'd be even better.
from pact-js.
@NomiJ to further what @mefellows is saying, Pact should never be run in the browser and needs to be run in a node environment. If you are doing unit tests with angular, you'll need something to run pact-node first (could be done with the build tool or npm scripts), then use pact-js to communicate the interactions with it. It could also be done using protractor if you want to do end to end tests since protractor runs fully in node.
from pact-js.
@NomiJ have you got any update on this?
from pact-js.
Hi,
Sorry for late reply. Explanation make sense. Due to shortage of time I ended up moving to Depreciated DSL here (https://github.com/DiUS/pact-consumer-js-dsl), yet would definitely like to upgrade to maintained package. I guess, i can always spawn the server as a separate process or gulp task. I will be creating a example soon and share it with you.
from pact-js.
I think i am missing something basic. Here I have created a basic angular2 App created with Angular-Cli (Release 1.0). I added @pact-foundation/pact-js and pact dependencies and created a basic "SayHello" test scenario.
https://github.com/NomiJ/Pact-Angular2-Example/blob/master/src/app/animal.service.spec.ts
Now running ng test outputs this
`
WARNING in .//source-map-support/source-map-support.js/source-map-support/source-map-support.js 474:15-32
Module not found: Error: Can't resolve 'module' in '/Users/nomi/Desktop/curveTomorrow/Pact-Angular2-Example/node_modules/source-map-support'
@ ./
@ .//bunyan/lib/bunyan.js/@pact-foundation/pact-node/src/logger.js
@ ./
@ .//@pact-foundation/pact-node/src/pact.js/pact/src/pact.js
@ ./
@ ./src/app/animal.service.spec.ts
@ ./src .spec.ts$
@ ./src/test.ts
WARNING in ./~/pact/src/common/config.js
21:19-44 Critical dependency: the request of a dependency is an expression
WARNING in ./~/@pact-foundation/pact-node/src/publisher.js
163:12-24 Critical dependency: the request of a dependency is an expression
WARNING in ./~/@pact-foundation/pact-mock-service/index.js
7:17-37 Critical dependency: the request of a dependency is an expression
WARNING in ./~/@pact-foundation/pact-provider-verifier/index.js
7:17-37 Critical dependency: the request of a dependency is an expression
ERROR in .//@pact-foundation/pact-node/src/server.js/@pact-foundation/pact-node/src/server.js 8:6-30
Module not found: Error: Can't resolve 'child_process' in '/Users/nomi/Desktop/curveTomorrow/Pact-Angular2-Example/node_modules/@pact-foundation/pact-node/src'
@ ./
@ .//@pact-foundation/pact-node/src/pact.js/pact/src/pact.js
@ ./
@ ./src/app/animal.service.spec.ts
@ ./src .spec.ts$
@ ./src/test.ts
ERROR in .//@pact-foundation/pact-node/src/verifier.js/@pact-foundation/pact-node/src/verifier.js 6:6-30
Module not found: Error: Can't resolve 'child_process' in '/Users/nomi/Desktop/curveTomorrow/Pact-Angular2-Example/node_modules/@pact-foundation/pact-node/src'
@ ./
@ .//@pact-foundation/pact-node/src/pact.js/pact/src/pact.js
@ ./
@ ./src/app/animal.service.spec.ts
@ ./src .spec.ts$
@ ./src/test.ts
28 02 2017 22:42:02.590:ERROR [karma]: { Error
at MemoryFileSystem.readFileSync (/Users/nomi/Desktop/curveTomorrow/Pact-Angular2-Example/node_modules/memory-fs/lib/MemoryFileSystem.js:107:10)
at MemoryFileSystem.(anonymous function) [as readFile] (/Users/nomi/Desktop/curveTomorrow/Pact-Angular2-Example/node_modules/memory-fs/lib/MemoryFileSystem.js:300:34)
at doRead (/Users/nomi/Desktop/curveTomorrow/Pact-Angular2-Example/node_modules/karma-webpack/lib/karma-webpack.js:205:29)
at Plugin.readFile (/Users/nomi/Desktop/curveTomorrow/Pact-Angular2-Example/node_modules/karma-webpack/lib/karma-webpack.js:210:7)
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
code: 'ENOENT',
errno: 34,
message: 'no such file or directory',
path: '/karma_webpack/src/polyfills.ts' }
28 02 2017 22:42:02.607:ERROR [karma]: { Error
at MemoryFileSystem.readFileSync (/Users/nomi/Desktop/curveTomorrow/Pact-Angular2-Example/node_modules/memory-fs/lib/MemoryFileSystem.js:107:10)
at MemoryFileSystem.(anonymous function) [as readFile] (/Users/nomi/Desktop/curveTomorrow/Pact-Angular2-Example/node_modules/memory-fs/lib/MemoryFileSystem.js:300:34)
at doRead (/Users/nomi/Desktop/curveTomorrow/Pact-Angular2-Example/node_modules/karma-webpack/lib/karma-webpack.js:205:29)
at Plugin.readFile (/Users/nomi/Desktop/curveTomorrow/Pact-Angular2-Example/node_modules/karma-webpack/lib/karma-webpack.js:210:7)
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
code: 'ENOENT',
errno: 34,
message: 'no such file or directory',
path: '/karma_webpack/src/test.ts' }`
My Environment:
@angular/cli: 1.0.0-rc.0 node: 7.0.0 os: darwin x64 @angular/common: 2.4.8 @angular/compiler: 2.4.8 @angular/core: 2.4.8 @angular/forms: 2.4.8 @angular/http: 2.4.8 @angular/platform-browser: 2.4.8 @angular/platform-browser-dynamic: 2.4.8 @angular/router: 3.4.8 @angular/cli: 1.0.0-rc.0 @angular/compiler-cli: 2.4.8 npm: 4.0.1
If i uninstall "@pact-foundation/pact-node", I get pact complaining like
ERROR in ./~/pact/src/pact.js Module not found: Error: Can't resolve '@pact-foundation/pact-node' in '/Users/nomi/Desktop/curveTomorrow/Pact-Angular2-Example/node_modules/pact/src' @ ./~/pact/src/pact.js 16:23-60 @ ./src/app/animal.service.spec.ts @ ./src \.spec\.ts$ @ ./src/test.ts
from pact-js.
Any update?
from pact-js.
OK part of the problem here is that both the consumer and the provider side of Pact JS must have access to a runtime environment outside of the browser (it needs to be able to spin up web servers and command-line utilities) - this use case is similar to Karma.
Take a look at the karma test for an example of how to do this, but for now I don't think it is possible to do what you want to do with the pact
npm package.
That being said, the code exists and is published as a release. You could certainly pull this down, and use the pact-karma
package for this. I'll raise an issue to rename it because AFAIK there is nothing Karma specific in it.
(You might be able to do something dodgey like const PactWeb = require('pact/dist/pact.web.js');
but this is getting into juggling chainsaw territory - do it at your own risk).
from pact-js.
I am in the same boat, any help is appreciated
from pact-js.
Hi there,
I've just pushed up a test branch https://github.com/pact-foundation/pact-js/tree/feature/pact-web that avoids pulling in the Pact Node library - the cause of all of the above errors.
Could you please test out pointing to this GH branch instead of the published package to see if this addresses your issues?
You'll need to do something like the following to your package.json
:
"devDependencies": {
"pact": "pact-foundation/pact-js#feature\/pact-web",
}
And when you create your Pact object:
provider = Pact({
consumer: 'Karma Jasmine',
provider: 'Hello',
web: true // <- this is the bit that matters
});
The bits that use pact-node are now wrapped inside functions that shouldn't be called by your code, I'm hoping that dead code elimination from tools like Webpack, Browserify or the Angular tooling should prune these imports. Else, we'll need a separate module release for this purpose.
from pact-js.
sure, i will test and report back
from pact-js.
from pact-js.
do i need keep this?
>> "@pact-foundation/pact-node": "4.8.0",
Thats how the current package.json looks like
"devDependencies": { "@angular/cli": "1.0.0-rc.0", "@angular/compiler-cli": "^2.4.0", "@pact-foundation/pact-node": "4.8.0", "@types/jasmine": "2.5.38", "@types/node": "~6.0.60", "codelyzer": "~2.0.0", "jasmine-core": "~2.5.2", "jasmine-spec-reporter": "~3.2.0", "karma": "~1.4.1", "karma-chrome-launcher": "~2.0.0", "karma-cli": "~1.0.1", "karma-coverage-istanbul-reporter": "^0.2.0", "karma-jasmine": "~1.1.0", "karma-jasmine-html-reporter": "^0.2.2", "pact": "pact-foundation/pact-js#feature\/pact-web", "protractor": "~5.1.0", "ts-node": "~2.0.0", "tslint": "~4.4.2", "typescript": "~2.0.0" }
from pact-js.
from pact-js.
Probably its a must a to run the mock server for tests to execute correctly, yet, i did not do it, considering the error
`
ERROR in .//@pact-foundation/pact-node/src/server.js/@pact-foundation/pact-node/src/server.js 8:6-30
Module not found: Error: Can't resolve 'child_process' in '/private/tmp/Pact-Angular2-Example/node_modules/@pact-foundation/pact-node/src'
@ ./
@ .//@pact-foundation/pact-node/src/pact.js/pact/src/pact.js
@ ./
@ ./src/app/animal.service.spec.ts
@ ./src .spec.ts$
@ ./src/test.ts
ERROR in .//@pact-foundation/pact-node/src/verifier.js/@pact-foundation/pact-node/src/verifier.js 6:6-30
Module not found: Error: Can't resolve 'child_process' in '/private/tmp/Pact-Angular2-Example/node_modules/@pact-foundation/pact-node/src'
@ ./
@ .//@pact-foundation/pact-node/src/pact.js/pact/src/pact.js
@ ./
@ ./src/app/animal.service.spec.ts
@ ./src .spec.ts$
@ ./src/test.ts`
Just to be sure, after npm install, i verified existence of your recent changes in pact.js, (addition of web ).
from pact-js.
What is pact-karma.js is about? Since Angular2 uses karma in my template. I checked your sample for karma-jasmine, yet it seems to load file from dist, in karma.conf.js, which probably require running npm dist
, to load pact.web.js from it. Is that how it suppose to be?
Would really appreciate a Typescript or angular2 sample from pact team.
from pact-js.
Pact Karma is a module that will automatically start a Mock Server for Karma tests. You can pull that in with the npm package karma-pact
.
The pact-karma.js file is the way to run Pact in a Browser (or non-Node environment). I'm thinking that it might make more sense to rename this, since there's no reason why it can't be used in non-Karma environments.
yet it seems to load file from dist, in karma.conf.js, which probably require runningnpm dist, to load pact.web.js from it. Is that how it suppose to be?
You could, although it has a release for the DSL. I'm not sure why this isn't released as an npm or bower style package, I'm following this up separately.
The Pact Karma plugin which manages the Mock Server has an npm package that you can pull down.
This is the ideal way to approach this.
from pact-js.
OK, just had a chat with the original author of the Karma stuff. I'm looking into how we can release that thing separately. For now, you'll need to find a manual way of pulling down that pact.web.js
file.
Sorry about the confusion!
from pact-js.
Hi @NomiJ, @jimishah , I have renamed the karma package to pact-web
and published a test package to https://www.npmjs.com/package/pact-web.
Would either of you care to give this a try?
from pact-js.
Hey @mefellows,
Thanxx
Got this working with the following package.json:
{
..
"karma-pact": "0.0.7",
"karma-phantomjs-launcher": "~1.0.4",
"pact": "^2.5.0",
"pact-web": "^2.5.0",
..
}
In my client.spec.ts I use:
let Pact = require('pact-web')
let provider = Pact({ consumer: 'Karma Jasmine', provider: 'Hello', web: true })
from pact-js.
Excellent!
from pact-js.
Also works for me. Anyone looking for example can look at
from pact-js.
from pact-js.
Hey @NomiJ this is not working for me. I'm using angular2 and Karma+Jasmine. is this outdated?
from pact-js.
I did not update the example, afterwards. I am sorry, its not working for you. Whats the problem that you are facing ?
from pact-js.
Related Issues (20)
- RFC: Remove CLI & Standalone API (Pact Standalone Tools - Ruby), and migrate into sister package pact-js-cli enhancement
- RFC: Support Alpine
- RFC: Pact JS V9.x - Update to latest V2 standalone / Include ARM64 Platforms HOT 1
- Because Maths: invalid pact specification version supplied: 5 HOT 8
- V4 Asynchronous Messages
- Bug: Corporate Proxy not supported during verification
- TypeError: ffi.pactffiMessageGivenWithParams is not a function HOT 2
- Support combining matching rules HOT 3
- `eachLike` behaves like `atLeastOneLike` when min is not explicitly set - contrary to documentation HOT 5
- payload changed by pact between consumer test and provider test HOT 6
- Message provider verification error: "Caught panic with error: failed printing to stdout" HOT 8
- CVE check denying [email protected] which is dependent on by pact-foundation/pact HOT 3
- V3 Matchers package missing matchers from V2
- BadSignature error when approaching broker on HTTPS HOT 5
- Vitest - Pact Verifier fails with 3 or more interactions HOT 8
- V4InteractionWithCompleteRequest is unimplemented HOT 9
- Allow using `new ArrayBuffer(0)` in withRequest.body to be honest in the contract tests HOT 1
- MatchersV3.reify doesn't extract payload from MatchersV3.nullValue() HOT 4
- Consumer test using application/x-www-form-urlencoded content type is being serialised as JSON
- Verify Pact-JS against pact-compatibility-suite
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pact-js.