Skip to content

Commit

Permalink
Upgrade test dependencies (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
TWiStErRob authored Sep 11, 2021
1 parent 62c6c4e commit 24c9417
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 77 deletions.
24 changes: 9 additions & 15 deletions .github/workflows/Heroku.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,31 +153,25 @@ jobs:
npm -v
npm install
- name: Install Compatible Chrome Driver
- name: Detect Compatible Chrome Driver
working-directory: Heroku/test/node_modules/webdriver-manager/selenium
run: |
echo ::group::Query tool versions
google-chrome --version
grep --version
curl --version
unzip -v
echo "Parsing current Chrome version: $(google-chrome --version)"
export CHROME_MINOR_VERSION=$(google-chrome --version | grep -oP '(?<=Google Chrome )(\d+\.\d+\.\d+)(?=\.\d+)')
export CHROME_FULL_VERSION=$(google-chrome --version)
echo "CHROME_FULL_VERSION=${CHROME_FULL_VERSION}" | tee --append $GITHUB_ENV
export CHROME_MINOR_VERSION=$(echo ${CHROME_FULL_VERSION} | grep -oP '(?<=Google Chrome )(\d+\.\d+\.\d+)(?=\.\d+)')
echo "CHROME_MINOR_VERSION=${CHROME_MINOR_VERSION}" | tee --append $GITHUB_ENV
echo "Querying latest Chrome Driver version: https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_MINOR_VERSION}"
export CHROME_DRIVER_VERSION=$(curl --output - --silent "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_MINOR_VERSION}")
echo "CHROME_DRIVER_VERSION=${CHROME_DRIVER_VERSION}" | tee --append $GITHUB_ENV
echo ::endgroup::
echo ::group::Install Chrome Driver for Selenium
# `npm run selenium:update -- --versions.chrome ${CHROME_DRIVER_VERSION}` should do normally but we get
# > I/update - chromedriver: unzipping chromedriver_92.0.4515.107.zip #(node:1727) UnhandledPromiseRejectionWarning: Error: Invalid filename
# Do a manual install instead:
echo "See listing at https://chromedriver.storage.googleapis.com/index.html?path=${CHROME_DRIVER_VERSION}/"
curl --output "chromedriver_${CHROME_DRIVER_VERSION}.zip" "https://chromedriver.storage.googleapis.com/${CHROME_DRIVER_VERSION}/chromedriver_linux64.zip"
unzip "chromedriver_${CHROME_DRIVER_VERSION}.zip"
mv "chromedriver" "chromedriver_${CHROME_DRIVER_VERSION}"
echo ::endgroup::
- name: Install Compatible Chrome Driver
working-directory: Heroku/test
run: |
npm run selenium:update -- --versions.chrome ${{ env.CHROME_DRIVER_VERSION }}
- name: Test
working-directory: Heroku
Expand Down
2 changes: 1 addition & 1 deletion Heroku/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
"devTest:backend": "gradlew :backend:endpoint:run --args \"../../deploy/static ../../test/fake-data\""
},
"devDependencies": {
"npm-run-all": "4.1.1"
"npm-run-all": "4.1.5"
}
}
3 changes: 3 additions & 0 deletions Heroku/test/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015"]
}
42 changes: 14 additions & 28 deletions Heroku/test/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
## Environment setup
Since the dependencies are old some trickery is necessary. In the package.json there are hardcoded version numbers.

`--versions.standalone 3.141.59` is the latest available Selenium driver that's compatible with this runner.

`--versions.chrome 92.0.4515.107` is a compatible Chrome Driver version which cannot be installed automatically, so need to do it manually:
* `Heroku\test$ npm install`
* Working directory: `Heroku\test\node_modules\webdriver-manager\selenium`
* Go to Chrome > Help > About and find version number: `x`
* Download the ZIP file as described here from `x`:
https://chromedriver.chromium.org/downloads/version-selection
`win32` will do, let's say it's version `y`.
* Rename it to `chromedriver_$y.zip`
* Extract and rename `chromedriver.exe` inside it to `chromedriver_$y.exe`
* Replace `package.json`'s Chrome version numbers with `y`.

This should help webdriver-manager's up-to-date check happy.
In the [package.json](package.json) there are hardcoded version number for everything for reproducibility. In case Chrome moves ahead a lot update the version number to match installed Chrome. To download a manual driver version, see https://chromedriver.chromium.org/downloads/version-selection.

## Run all tests

Expand All @@ -36,25 +21,26 @@ test$ npm run protractor

### IntelliJ IDEA

Create a Node.js run configuration with:
Create a Protractor run configuration in Ultimate.
Or in all versions: create a Node.js run configuration with:
* Working directory: `test` folder
* Javascript file: `node_modules\protractor\built\cli.js`
* Application parameters: `protractor.config.js`
* Node parameters: `--trace-warnings`

Debug attach from IntelliJ IDEA is not working with the following message:

> I/BlockingProxy - Starting BlockingProxy with args: --fork,--seleniumAddress,http://localhost:4444/wd/hub,--logDir,logs
> E/BlockingProxy - Error: listen EADDRINUSE :::64617
to fix it, change `bpRunner.js` this way:

```diff
+var execArgv = process.execArgv.filter(function(arg) {
+ return arg.indexOf('--debug-brk=') !== 0 && arg.indexOf('--inspect') !== 0; });
-this.bpProcess = child_process_1.fork(BP_PATH, args, { silent: true });
+this.bpProcess = child_process_1.fork(BP_PATH, args, { silent: true, execArgv });
```
I/launcher - Running 1 instances of WebDriver
I/hosted - Using the selenium server at http://localhost:4444/wd/hub
I/BlockingProxy - Starting BlockingProxy with args: --fork,--seleniumAddress,http://localhost:4444/wd/hub,--logDir,logs
E/BlockingProxy - Starting inspector on 127.0.0.1:54285 failed: address already in use
E/BlockingProxy - Exited with 12
E/BlockingProxy - signal null
E/launcher - Error: Error: BP exited with 12
at ChildProcess.bpProcess.on.on.on (test/node_modules/protractor/built/bpRunner.js:37:24)
```

to fix it, change `bpRunner.js` as described in [patch](bpRunner.js.patch.sed). It should run automatically on `npm install`.

## Upgrade to new Babel

Expand Down
36 changes: 36 additions & 0 deletions Heroku/test/bpRunner.js.patch.sed
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sed -z -r -f bpRunner.js.patch.sed -i node_modules/protractor/built/bpRunner.js
# sed script (of a single replace command) that
# * works on the whole input at once (-z)
# * uses extended regex syntax (-r)
# * is in a file so it can be documented (-f)
# * replaces the input file in place (-i)

# Expected input in bpRunner.js:
#```javascript
#class BlockingProxyRunner {
# ...
# this.bpProcess = child_process_1.fork(BP_PATH, args, { silent: true });
#```

# The script will replace the first and last lines into
#```javascript
# // HACKED -- begin
# var execArgv = process.execArgv.filter(function(arg) {
# return arg.indexOf('--debug-brk=') !== 0 && arg.indexOf('--inspect') !== 0;
# });
# this.bpProcess = child_process_1.fork(BP_PATH, args, { silent: true, execArgv });
# // HACKED -- end
#```

# Note: Each line end has to be unterminated with an escape, so sed handles multiline script correctly.
# Note: s/ has to be on one line, because otherwise it'll not match.
# Note: programming () {} . has to be escaped in search.
# Note: programming && and // has to be escaped in replacement.
s/this\.bpProcess = child_process_1\.fork\(BP_PATH, args, \{ silent: true \}\);/\
\/\/ HACKED -- begin\
var execArgv = process.execArgv.filter(function(arg) {\
return arg.indexOf('--debug-brk=') !== 0 \&\& arg.indexOf('--inspect') !== 0;\
});\
this.bpProcess = child_process_1.fork(BP_PATH, args, { silent: true, execArgv });\
\/\/ HACKED -- end\
/
36 changes: 18 additions & 18 deletions Heroku/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@
"repository": "local",
"scripts": {
"preinstall": "echo Installing Test dependencies",
"postinstall": "npm-run-all --serial selenium:update && echo Installed Test dependencies",
"postinstall": "echo Installing Selenium && npm run selenium:update && echo Hacking Backend dependencies && sed -r -f bpRunner.js.patch.sed -i node_modules/protractor/built/bpRunner.js && echo Installed Test dependencies",
"postupdate": "npm-run-all --serial selenium:update",
"start": "npm-run-all --race --parallel selenium protractor",
"selenium": "webdriver-manager --versions.standalone 3.141.59 --versions.chrome 93.0.4577.63 start",
"selenium:update": "webdriver-manager --versions.standalone 3.141.59 --versions.chrome 93.0.4577.63 update",
"selenium": "webdriver-manager --standalone false --gecko false --versions.chrome 93.0.4577.63 start",
"selenium:update": "webdriver-manager --standalone false --gecko false --versions.chrome 93.0.4577.63 update",
"protractor": "protractor protractor.config.js",
"inspect": "protractor --directConnect --elementExplorer protractor.config.js",
"test": "npm run test:jshint",
"test:jshint": "jshint --verbose --show-non-errors src"
},
"dependencies": {
"jasmine-expect": "3.8.3",
"jasmine-expect": "5.0.0",
"jasmine-expect-moment": "0.1.1",
"lodash": "4.17.10",
"moment": "2.22.2",
"protractor": "5.4.0",
"protractor-helpers": "1.1.473",
"protractor-browser-logs": "1.0.351",
"lodash": "4.17.21",
"moment": "2.29.1",
"protractor": "7.0.0",
"protractor-helpers": "1.1.813",
"protractor-browser-logs": "1.0.456",
"selenium-webdriver": "3.6.0"
},
"devDependencies": {
"@types/jasminewd2": "2.0.3",
"babel-core": "5.8.38",
"jasmine-spec-reporter": "4.2.1",
"npm-run-all": "4.1.3",
"protractor-screenshoter-plugin": "0.10.1",
"rimraf": "2.6.2",
"webdriver-manager": "12.0.6",
"jshint": "2.9.6",
"mocha": "5.2.0"
"@types/jasminewd2": "2.0.10",
"babel-core": "6.26.3",
"babel-preset-es2015": "6.24.1",
"jasmine-spec-reporter": "7.0.0",
"npm-run-all": "4.1.5",
"protractor-screenshoter-plugin": "0.10.3",
"webdriver-manager": "12.1.8",
"jshint": "2.13.1",
"mocha": "9.1.1"
}
}
4 changes: 2 additions & 2 deletions Heroku/test/protractor.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ function printTestingProgress() {
displayPending: true,
displayDuration: true,
displayErrorMessages: true,
displayStacktrace: true,
displayStacktrace: 'pretty',
},
summary: {
displaySuccessful: false,
displayFailed: true,
displayPending: false,
displayDuration: false,
displayErrorMessages: true,
displayStacktrace: false,
displayStacktrace: 'none',
},
}));
}
Expand Down
2 changes: 1 addition & 1 deletion Heroku/test/src/dialogs.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import app, { date, cinemas, films, performances, plans } from './dsl/app';
import app, { date, films, performances } from './dsl/app';

describe('Dialogs', function () {

Expand Down
2 changes: 1 addition & 1 deletion Heroku/test/src/films.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import app, { films as films } from './dsl/app';
import { anyWithText, noneWithText } from './helpers/protractor-filters';
import { anyWithText } from './helpers/protractor-filters';

function watchedFilm(film) {
return anyWithText(films.watched.items, film.getText());
Expand Down
20 changes: 10 additions & 10 deletions Heroku/test/src/helpers/protractor-filters.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
/**
* Matches the element to have a Bootstrap glyphicon element inside with the given icon name
* Matches any element in {@param elementList} that has the same text as the resolved value of {@param textPromise}.
* @param {ElementArrayFinder} elementList
* @param {Promise<string>} textPromise the end of `glyphicon-name`
* @param {Promise<string>} textPromise
* @returns {Promise<boolean>}
*/
export function anyWithText(elementList, textPromise) {
//noinspection JSValidateTypes reduce will resolve correctly: `false` + `||` -> boolean
return elementList.reduce(function (acc, elem) {
return textPromise.then(function (resolvedText) {
return textPromise.then(function (resolvedText) {
return elementList.reduce(function (acc, elem) {
return elem.getText().then(function (elemName) {
return acc || resolvedText === elemName;
});
});
}, false);
}, false);
});
}

/**
* Matches the element to have a Bootstrap glyphicon element inside with the given icon name
* Checks if there are no elements in {@param elementList} that have the same text as the resolved value of {@param textPromise}.
* @param {ElementArrayFinder} elementList
* @param {Promise<string>} text the end of `glyphicon-name`
* @param {Promise<string>} textPromise
* @returns {Promise<boolean>}
*/
export function noneWithText(elementList, text) {
return anyWithText(elementList, text).then((result) => !result);
export function noneWithText(elementList, textPromise) {
return anyWithText(elementList, textPromise).then((result) => !result);
}
2 changes: 1 addition & 1 deletion Heroku/test/src/plans.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ describe('Planner display', function () {

cinemaPlan.each((plan) => {
const titles = plan.scheduleMovies.all(by.className('film-title'));
expect(anyWithText(titles, firstMovieInPlan.title.getText())).toBeTrue();
expect(anyWithText(titles, firstMovieInPlan.title.getText())).toBe(true);
});
expect(cinemaPlan.moreAll).toBeDisplayed();
expect(cinemaPlan.moreN).toBeDisplayed();
Expand Down

0 comments on commit 24c9417

Please sign in to comment.