Skip to content

Commit

Permalink
e2e testing
Browse files Browse the repository at this point in the history
  • Loading branch information
buu700 committed Jan 14, 2018
1 parent 2ab9515 commit d64ba3e
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 29 deletions.
4 changes: 4 additions & 0 deletions commands/ngprojectinit.sh
@@ -1,6 +1,10 @@
#!/bin/bash


if [ "$(ls -A node_modules)" ] ; then
exit
fi

rm src/favicon.ico 2> /dev/null
cp ../shared/favicon.ico src/

Expand Down
32 changes: 29 additions & 3 deletions commands/serve.sh
Expand Up @@ -7,25 +7,46 @@ cd $(cd "$(dirname "$0")" ; pwd)/..

eval "$(./commands/getgitdata.sh)"

e2e=''
site=''
if [ "${1}" == '--e2e' ] ; then
e2e=true
shift
fi
if [ "${1}" == 'cyph.ws' ] || [ "${1}" == 'cyph.com' ] ; then
site="${1}"
shift
fi
args="${@}"

if [ "${e2e}" ] && [ ! "${site}" ] ; then
fail 'Must specify a site when serving with --e2e'
fi

ngserve () {
ngserveInternal () {
if [ "${e2e}" ] ; then
ng e2e "${@}"
else
ng serve "${@}"
fi

return $?
}

cd "${1}"
../commands/ngprojectinit.sh
echo -e '\n\n\n'
ng serve \
ngserveInternal \
--host '0.0.0.0' \
--live-reload false \
--no-aot \
--port "${2}" \
--no-sourcemaps \
$(if [ -f /windows ] ; then echo '--poll 1000' ; fi) \
${args}

return $?
}


Expand Down Expand Up @@ -59,8 +80,13 @@ for arr in 'cyph.ws 42002' 'cyph.com 42001' ; do
read -ra arr <<< "${arr}"

if [ ! "${site}" ] || [ "${site}" == "${arr[0]}" ] ; then
ngserve "${arr[0]}" "${arr[1]}" &
sleep 60
if [ "${e2e}" ] ; then
ngserve "${arr[0]}" "${arr[1]}"
exit $?
else
ngserve "${arr[0]}" "${arr[1]}" &
sleep 60
fi
fi
done

Expand Down
12 changes: 10 additions & 2 deletions commands/test.sh
Expand Up @@ -11,7 +11,15 @@ export CHROME_BIN="$(node -e 'console.log(require("puppeteer").executablePath())

cd cyph.ws
../commands/ngprojectinit.sh
ng test --browsers ChromeHeadless
checkfail

if [ "${1}" != '--e2e' ] ; then
ng test --browsers ChromeHeadless
checkfail
fi

if [ "${1}" != '--unit' ] ; then
../commands/serve.sh --e2e cyph.ws
checkfail
fi

pass
12 changes: 6 additions & 6 deletions cyph.com/e2e/app.e2e-spec.ts
@@ -1,15 +1,15 @@
import {Cyph.WsPage} from './app.po';
import {CyphPage} from './app.po';


describe('cyph.com App', () => {
let page: Cyph.WsPage;
describe('cyph.com', () => {
let page: CyphPage;

beforeEach(() => {
page = new Cyph.WsPage();
page = new CyphPage();
});

it('should display message saying app works', () => {
it('should display footer', async () => {
page.navigateTo();
expect(page.getParagraphText()).toEqual('app works!');
expect(await page.getParagraphText()).toEqual('© Cyph 2018');
});
});
9 changes: 5 additions & 4 deletions cyph.com/e2e/app.po.ts
@@ -1,12 +1,13 @@
import {browser, element, by} from 'protractor';


export class Cyph.WsPage {
public navigateTo () : void {
export class CyphPage {
public async navigateTo () : Promise<any> {
await browser.waitForAngularEnabled(false);
return browser.get('/');
}

public getParagraphText () : void {
return element(by.css('app-root h1')).getText();
public async getParagraphText () : Promise<string> {
return element(by.css('footer > div > span:first-child')).getText();
}
}
8 changes: 6 additions & 2 deletions cyph.com/protractor.conf.js
Expand Up @@ -4,12 +4,16 @@
const {SpecReporter} = require('jasmine-spec-reporter');

exports.config = {
allScriptsTimeout: 11000,
allScriptsTimeout: 30000,
specs: [
'./e2e/**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome'
browserName: 'chrome',
chromeOptions: {
args: ['--headless', '--disable-gpu', '--window-size=1280,800'],
binary: process.env.CHROME_BIN
}
},
directConnect: true,
baseUrl: 'http://localhost:42001/',
Expand Down
12 changes: 6 additions & 6 deletions cyph.ws/e2e/app.e2e-spec.ts
@@ -1,15 +1,15 @@
import {Cyph.WsPage} from './app.po';
import {CyphPage} from './app.po';


describe('cyph.ws App', () => {
let page: Cyph.WsPage;
describe('Cyph', () => {
let page: CyphPage;

beforeEach(() => {
page = new Cyph.WsPage();
page = new CyphPage();
});

it('should display message saying app works', () => {
it('should display footer', async () => {
page.navigateTo();
expect(page.getParagraphText()).toEqual('app works!');
expect(await page.getParagraphText()).toEqual('© Cyph 2018');
});
});
9 changes: 5 additions & 4 deletions cyph.ws/e2e/app.po.ts
@@ -1,12 +1,13 @@
import {browser, element, by} from 'protractor';


export class Cyph.WsPage {
public navigateTo () : void {
export class CyphPage {
public async navigateTo () : Promise<any> {
await browser.waitForAngularEnabled(false);
return browser.get('/');
}

public getParagraphText () : void {
return element(by.css('app-root h1')).getText();
public async getParagraphText () : Promise<string> {
return element(by.css('cyph-footer a > span:first-child')).getText();
}
}
8 changes: 6 additions & 2 deletions cyph.ws/protractor.conf.js
Expand Up @@ -4,12 +4,16 @@
const {SpecReporter} = require('jasmine-spec-reporter');

exports.config = {
allScriptsTimeout: 11000,
allScriptsTimeout: 30000,
specs: [
'./e2e/**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome'
browserName: 'chrome',
chromeOptions: {
args: ['--headless', '--disable-gpu', '--window-size=1280,800'],
binary: process.env.CHROME_BIN
}
},
directConnect: true,
baseUrl: 'http://localhost:42002/',
Expand Down
8 changes: 8 additions & 0 deletions docker.js
Expand Up @@ -502,6 +502,14 @@ switch (args.command) {
case 'test':
commandAdditionalArgs.push('-p');
commandAdditionalArgs.push('9876:9876');
commandAdditionalArgs.push('-p');
commandAdditionalArgs.push('42000:42000');
commandAdditionalArgs.push('-p');
commandAdditionalArgs.push('42001:42001');
commandAdditionalArgs.push('-p');
commandAdditionalArgs.push('42002:42002');
commandAdditionalArgs.push('-p');
commandAdditionalArgs.push('44000:44000');
break;

case 'updatecircleci':
Expand Down
1 change: 1 addition & 0 deletions node_modules

0 comments on commit d64ba3e

Please sign in to comment.