@shahabganji
Thanks works great
But I think you should get the port from aurelia.json
.
npm i ps-node -D
npm i find-process -D
"scripts": {
"e2e": "au cypress --run --start"
}
// @ts-ignore
import * as cypress from 'cypress';
import * as config from '../../cypress.config';
import { CLIOptions } from 'aurelia-cli';
// @ts-ignore
import * as cfg from '../aurelia.json';
let find = require('find-process');
let ps = require('ps-node');
import * as run from './run';
export default (cb) => {
let hasRunProject = process.argv.find(x => x === "--start") || false;
if (hasRunProject) {
run.default();
}
if (CLIOptions.hasFlag('run')) {
cypress
.run(config)
.then(results => {
(results.totalFailed === 0 ? cb() : cb('Run failed!'));
find('port', cfg.platform.port)
.then(function (list) {
if (!list.length) {
console.log(`port ${cfg.platform.port} is free now`);
} else {
console.log(`%s is listening port ${cfg.platform.port}`, JSON.stringify(list[0]));
var isWin = process.platform === "win32";
// kill the process
if (isWin) {
ps.kill(list[0].pid, { signal: 'SIGHUP' }, () => { });
process.exit();
}
else {
ps.kill(list[0].pid, () => { });
}
}
})
}
)
.catch(cb);
} else {
cypress.open(config);
}
};