Migrating from:
"@pact-foundation/pact-node": "4.12.0",
"karma-pact": "0.0.7",
to:
"@pact-foundation/pact-node": "6.19.7",
"@pact-foundation/karma-pact": "2.1.5",
karma.conf.js:
// Karma configuration
// Generated on Mon Jul 07 2014 11:06:02 GMT+0100 (BST)
var path = require('path');
console.log('------------------ CONFIG STARTED');
module.exports = function (config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '../../../../',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha', 'pact', 'requirejs'],
// browserNoActivityTimeout: 60000,
plugins: [
'karma-*',
'@pact-foundation/karma-pact'
],
pact: [
{
port: 8990,
log: path.resolve(process.cwd(), 'logs', 'pact-tests.user-auth.log'),
dir: path.resolve(process.cwd(), 'build/pacts/json'),
logLevel: 'DEBUG',
spec: 2
}
],
// list of files / patterns to load in the browser
files: [
{pattern: 'tests/specs/**/*.js', included: false},
{pattern: 'node_modules/chai/chai.js', included: false},
{pattern: 'node_modules/sinon/pkg/sinon.js', included: false},
{pattern: 'node_modules/sweep.js/build/sweep.js', included: false},
{pattern: 'node_modules/signals/dist/signals.js', included: false},
{pattern: 'node_modules/infuse.js/src/infuse.js', included: false},
{pattern: 'node_modules/q/q.js', included: false},
{pattern: 'node_modules/reqwest/reqwest.js', included: false},
{pattern: 'node_modules/@pact-foundation/pact/pact-web.js', included: false},
{pattern: 'node_modules/axios/dist/axios.js', included: false},
{pattern: 'node_modules/squirejs/src/Squire.js', included: false},
{pattern: 'public/**/*.js', included: false, served: true},
{pattern: 'public/js/app/modules/**/*.json', included: false, served: true},
{pattern: 'tests/pact/interactions/**/*.js', included: false, served: true},
'tests/assets/pact-test-helper.js',
'tests/pact/karma/user-auth/runner.js'
],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['mocha'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_ERROR,
// enable / disable watching file and executing tests whenever any file chan ges
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['ChromeHeadless'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
});
};
Command run:
karma start tests/pact/karma/user-auth/karma.conf.js --single-run --no-browser --verbose
Console output:
------------------ CONFIG STARTED
[2018-07-25T13:59:23.378Z] INFO: pact-node@6.19.7/93392 on C02R84BCG8WP:
Creating Pact Server with options:
port = 8990,
log = /Users/martcham/edna/logs/pact-tests.user-auth.log,
dir = /Users/martcham/edna/build/pacts/json,
logLevel = DEBUG,
spec = 2,
pactFileWriteMode = overwrite,
ssl = false,
cors = false,
host = localhost
[2018-07-25T13:59:23.394Z] INFO: pact-node@6.19.7/93392 on C02R84BCG8WP: Created './standalone/darwin-1.52.2/bin/pact-mock-service service --port '8990' --log '/Users/martcham/edna/logs/pact-tests.user-auth.log' --pact_dir '/Users/martcham/edna/build/pacts/json' --log-level 'DEBUG' --pact_specification_version '2' --pact-file-write-mode 'overwrite' --host 'localhost'' process with PID: 93433
---------------- STARTED function
^C[2018-07-25T13:59:29.517Z] INFO: pact-node@6.19.7/93392 on C02R84BCG8WP: Removing all Pact servers.
[2018-07-25T13:59:29.518Z] INFO: pact-node@6.19.7/93392 on C02R84BCG8WP: Removing Pact with PID: 93433
The karma-pact/src/index.js:
var Promise = require("bluebird");
var deasync = require('deasync');
var runPactMockServer = function (pacts, logger) {
var log = logger.create('pact');
pacts = pacts || [];
// If pact options is object, wrap in array
if (!Array.isArray(pacts)) {
pacts = [pacts];
}
var done = false;
Promise.all(pacts.map(function (pact) {
var server = wrapper.createServer(pact);
return server.start().then(function () {
log.info('Pact Mock Server running on port: ' + server.options.port);
console.log('---------------- STARTED', typeof log.info);
}, function (err) {
console.log('---------------- NOT STARTED', err);
log.error('Error while trying to run karma-pact: ' + err);
});
})).then(function() {
console.log('------------ ALL DONE');
done = true;
});
deasync.loopWhile(function(){return !done;});
};
runPactMockServer.$inject = ['config.pact', 'logger'];
module.exports = {
'framework:pact': ['factory', runPactMockServer]
};
There appears to be an issue with deasync as when I edit the index to:
var Promise = require("bluebird");
var deasync = require('deasync');
var runPactMockServer = function (pacts, logger) {
var log = logger.create('pact');
pacts = pacts || [];
// If pact options is object, wrap in array
if (!Array.isArray(pacts)) {
pacts = [pacts];
}
var done = false;
var server = wrapper.createServer(pacts[0])
server.start().then(function () {
console.log('---------------- STARTED');
log.info('Pact Mock Server running on port: ' + server.options.port);
}, function (err) {
console.log('---------------- NOT STARTED', err);
log.error('Error while trying to run karma-pact: ' + err);
})
};
runPactMockServer.$inject = ['config.pact', 'logger'];
module.exports = {
'framework:pact': ['factory', runPactMockServer]
};
The runner is started and the console output is:
------------------ CONFIG STARTED
[2018-07-25T16:25:07.359Z] INFO: pact-node@6.19.7/94711 on C02R84BCG8WP:
Creating Pact Server with options:
port = 8990,
log = /Users/martcham/edna/logs/pact-tests.user-auth.log,
dir = /Users/martcham/edna/build/pacts/json,
logLevel = DEBUG,
spec = 2,
pactFileWriteMode = overwrite,
ssl = false,
cors = false,
host = localhost
[2018-07-25T16:25:07.367Z] INFO: pact-node@6.19.7/94711 on C02R84BCG8WP: Created './standalone/darwin-1.52.2/bin/pact-mock-service service --port '8990' --log '/Users/martcham/edna/logs/pact-tests.user-auth.log' --pact_dir '/Users/martcham/edna/build/pacts/json' --log-level 'DEBUG' --pact_specification_version '2' --pact-file-write-mode 'overwrite' --host 'localhost'' process with PID: 94713
START:
---------------- STARTED
HeadlessChrome 0.0.0 (Mac OS X 10.12.6) LOG: '--------------- RUNNER STARTED'
HeadlessChrome 0.0.0 (Mac OS X 10.12.6) ERROR
{
"message": "Uncaught Error: Script error for \"Pact\", needed by: tests/specs/modules/sign-in/services/user-auth.js, tests/specs/modules/sign-in/services/user-token.js, tests/specs/modules/sign-in/services/user-pairing-code.js\nhttp://requirejs.org/docs/errors.html#scripterror\nat node_modules/requirejs/require.js:143:9\n\nError: Script error for \"Pact\", needed by: tests/specs/modules/sign-in/services/user-auth.js, tests/specs/modules/sign-in/services/user-token.js, tests/specs/modules/sign-in/services/user-pairing-code.js\nhttp://requirejs.org/docs/errors.html#scripterror\n at makeError (node_modules/requirejs/require.js:168:17)\n at HTMLScriptElement.onScriptError (node_modules/requirejs/require.js:1738:36)",
"str": "Uncaught Error: Script error for \"Pact\", needed by: tests/specs/modules/sign-in/services/user-auth.js, tests/specs/modules/sign-in/services/user-token.js, tests/specs/modules/sign-in/services/user-pairing-code.js\nhttp://requirejs.org/docs/errors.html#scripterror\nat node_modules/requirejs/require.js:143:9\n\nError: Script error for \"Pact\", needed by: tests/specs/modules/sign-in/services/user-auth.js, tests/specs/modules/sign-in/services/user-token.js, tests/specs/modules/sign-in/services/user-pairing-code.js\nhttp://requirejs.org/docs/errors.html#scripterror\n at makeError (node_modules/requirejs/require.js:168:17)\n at HTMLScriptElement.onScriptError (node_modules/requirejs/require.js:1738:36)"
}
Finished in 0.138 secs / 0 secs @ 17:25:08 GMT+0100 (BST)
Any help would be greatly appreciated!
Migrating from:
"@pact-foundation/pact-node": "4.12.0",
"karma-pact": "0.0.7",
to:
"@pact-foundation/pact-node": "6.19.7",
"@pact-foundation/karma-pact": "2.1.5",
karma.conf.js:
Command run:
karma start tests/pact/karma/user-auth/karma.conf.js --single-run --no-browser --verboseConsole output:
The karma-pact/src/index.js:
There appears to be an issue with deasync as when I edit the index to:
The runner is started and the console output is:
Any help would be greatly appreciated!