Skip to content

Create tests GH Actions workflow to run tests #3

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

Merged
merged 9 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Tests

on: [push]

jobs:
unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Cache node modules
uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Install dependencies (npm ci)
run: npm ci
working-directory: ./phone-store
- name: Run unit tests (npm run test)
run: npm run test -- --no-watch --no-progress --browsers=ChromeHeadlessCI
working-directory: ./phone-store
e2e-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Cache node modules
uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Install dependencies (npm ci)
run: npm ci
working-directory: ./phone-store
- name: Run e2e tests
run: npm run e2eci
working-directory: ./phone-store
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ We will also not provide a complete tutorial on E2E tests with protractor or uni
- :question: This creates a directory called `phone-store` in the project. Do we want to change the name to `client` to be more like our later structures?
- At this point you can go into the `phone-store` directory and run `ng server` and see our little project! :smile: It of course doesn't actually _do_ anything interesting yet, but it does work.

### Setup GitHub Actions

@floogulinc set up the GitHub Actions based on work done in S20.
These are all laid out in [this pull request](https://github.com/UMM-CSci-3601/revised-angular-tutorial/pull/3).

For reasons we don't fully understand, this requires installing
some `webdriver-manager` binaries that didn't get installed on
their own. Without them, we can't run the `e2e` tests.

Running:

```bash
node_modules/protractor/bin/webdriver-manager update
```

installed the necessary binaries and all the tests ran and passed.

## Start making components

The tutorial starts you off with two components:
Expand Down
3 changes: 2 additions & 1 deletion phone-store/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "phone-store:serve"
"devServerTarget": "phone-store:serve",
"webdriverUpdate": false
},
"configurations": {
"production": {
Expand Down
15 changes: 15 additions & 0 deletions phone-store/e2e/protractor-ci.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const config = require('./protractor.conf').config;

config.capabilities = {
browserName: 'chrome',
chromeOptions: {
args: ['--headless', '--no-sandbox']
}
};

config.highlightDelay = undefined;

config.seleniumServerJar = process.env.SELENIUM_JAR_PATH;
config.chromeDriver = process.env.CHROMEWEBDRIVER + '/chromedriver';

exports.config = config;
8 changes: 5 additions & 3 deletions phone-store/e2e/protractor.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ exports.config = {
capabilities: {
browserName: 'chrome'
},
directConnect: true,
directConnect: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why you changed this from the default. I can see why you might want to from what I've read on-line, but then I'm not sure why they have it set to true in the default config?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We set this and moved to going through selenium in lab 3, 4, and the iteration template so we could use the element highlighting built into protractor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is necessary to make the highlighting work? Would it run (appreciably) faster if we didn't have that?

I'm not convinced that students use the highlighting much, especially once there are a lot of tests, although @kklamberty probably has differing opinions on that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's not needed then we could remove it and also possibly change back a lot of the custom stuff we did to allow for the highlighting but we would want to do a good amount of testing, especially on lab machines, to make sure it still works correctly with the more default setup.

baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
Expand All @@ -28,5 +28,7 @@ exports.config = {
project: require('path').join(__dirname, './tsconfig.json')
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
}
};
},
useBlockingProxy: true,
highlightDelay: 200 // How long it waits and highlights before interacting with an element
};
6 changes: 6 additions & 0 deletions phone-store/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ module.exports = function (config) {
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
customLaunchers: {
ChromeHeadlessCI: {
base: 'ChromeHeadless',
flags: ['--no-sandbox']
}
},
singleRun: false,
restartOnFileChange: true
});
Expand Down
2 changes: 2 additions & 0 deletions phone-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"pree2e": "node node_modules/protractor/bin/webdriver-manager -- update --gecko false",
"e2eci": "ng e2e --protractor-config=e2e/protractor-ci.conf.js",
"postinstall": "ngcc"
},
"private": true,
Expand Down