Skip to content

Commit

Permalink
Update deps.sh and run.sh, begin working on E2E tests and packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
David Evans authored and Your Name committed Jan 22, 2019
1 parent 3073d82 commit c21d9f2
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
nodejs 6.14.4
nodejs 11.6.0
ruby 2.4.0
29 changes: 27 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,19 @@ You can run Postfacto locally at [https://localhost:3000]() by running:
./run.sh
```

The admin dashboard will be available at [https://localhost:4000/admin](). You can create an admin user using the following rake task in the `api` directory:
Or to use real authentication (this will use no authentication unless `config.js` has a Google Auth client ID):

```bash
./run.sh --real-auth
```

---

The admin dashboard will be available at [https://localhost:4000/admin]().

A default admin user '[email protected]' with password 'password' will be created

You can create other admin users using the following rake task in the `api` directory:

```bash
[email protected] ADMIN_PASSWORD=password rake admin:create_user
Expand All @@ -41,11 +53,24 @@ You can run the tests for the whole project in the root directory by simply runn
./test.sh
```

The following sections show how to run individual test suites during development.

### Web

To run the tests in "watch mode" (runs any tests touched by unstaged Git changes and re-runs tests when files change):

```bash
cd web
npm test
```

(this can also be written as `npm --prefix=web test` if you prefer).

To run all the tests:

```bash
cd web
gulp spec-app
CI=true npm test
```

### API
Expand Down
6 changes: 1 addition & 5 deletions PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ Thanks for contributing to postfacto. To speed up the process of reviewing your

* [ ] I have made this pull request to the `master` branch

* [ ] I have run all the API unit tests using `bundle exec rake` from the `/api` submodule.

* [ ] I have run all the WEB unit tests using `gulp spec-app` from the `/web` submodule.

* [ ] I have run all the acceptance tests using `gulp local-acceptance` from the `/web` submodule.
* [ ] I have run all the tests using `./test.sh`.

* [ ] I have added the [copyright headers](https://github.com/pivotal/postfacto/blob/master/license-header.txt) to each new file added
19 changes: 8 additions & 11 deletions deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@

set -e

pushd api
bundle install --without production
popd
BASE_DIR="$(dirname "$0")"

pushd web
npm install
popd
pushd "$BASE_DIR/api" >/dev/null
bundle install --without production
popd >/dev/null

pushd mock-google-server
npm install
popd
npm --prefix="$BASE_DIR/web" install
npm --prefix="$BASE_DIR/mock-google-server" install

pushd e2e
pushd "$BASE_DIR/e2e" >/dev/null
bundle install
popd
popd >/dev/null
2 changes: 1 addition & 1 deletion docker.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

docker run -it --entrypoint /bin/bash -p 3000:3000 -p 4000:4000 -v $(PWD):/postfacto postfacto/postfacto
docker run -it --entrypoint /bin/bash -p 3000:3000 -p 4000:4000 -v "$(pwd)":/postfacto postfacto/postfacto
7 changes: 3 additions & 4 deletions docker/postfacto/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,20 @@ RUN gem install bundler
## Install Node
RUN curl -sL https://deb.nodesource.com/setup_11.x | bash
RUN apt-get update && apt-get install -y nodejs
RUN npm install -g bower
RUN npm install -g gulp

# Install Chrome WebDriver
RUN CHROMEDRIVER_VERSION='2.38' && \
RUN CHROMEDRIVER_VERSION='2.45' && \
mkdir -p /opt/chromedriver-$CHROMEDRIVER_VERSION && \
curl -sS -o /tmp/chromedriver_linux64.zip http:https://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip && \
curl -sS -o /tmp/chromedriver_linux64.zip https:https://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip && \
unzip -qq /tmp/chromedriver_linux64.zip -d /opt/chromedriver-$CHROMEDRIVER_VERSION && \
rm /tmp/chromedriver_linux64.zip && \
chmod +x /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver && \
ln -fs /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver /usr/local/bin/chromedriver

# Install Google Chrome
RUN curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
echo "deb http:https://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list
echo "deb https:https://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list
RUN apt-get -yqq update && apt-get -yqq install google-chrome-stable && rm -rf /var/lib/apt/lists/*

# Install Sqlite dev tools
Expand Down
12 changes: 6 additions & 6 deletions package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

if [ -d "package" ]; then
if [[ -d "package" ]]; then
rm -r package
fi

Expand All @@ -11,8 +11,8 @@ mkdir package
# BUILD FRONT-END

pushd web
NODE_ENV=production gulp assets
gulp package
npm run build
cp ../humans.txt build
popd

# PWS
Expand All @@ -25,7 +25,7 @@ mkdir package/pws/assets

rm -rf api/tmp/*
cp -r api package/pws/assets/api
cp -r web/package package/pws/assets/web
cp -r web/build package/pws/assets/web

# PCF

Expand All @@ -37,7 +37,7 @@ mkdir package/pcf/assets

rm -rf api/tmp/*
cp -r api package/pcf/assets/api
cp -r web/package package/pcf/assets/web
cp -r web/build package/pcf/assets/web

# Heroku

Expand All @@ -47,7 +47,7 @@ chmod u+x package/heroku/deploy.sh

rm -rf api/tmp/*
cp -r api/* package/heroku/assets/api
cp -r web/package package/heroku/assets/web/public_html
cp -r web/build package/heroku/assets/web/public_html

# Docs

Expand Down
44 changes: 38 additions & 6 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,43 @@

set -e

pushd api
BASE_DIR="$(dirname "$0")"

EXIT_SCRIPT="";
trap "eval \"\$EXIT_SCRIPT\"; sleep 1; echo 'Shutdown complete.';" EXIT

ADMIN_USER='[email protected]'
ADMIN_PASS='password'

pushd "$BASE_DIR/api" >/dev/null
bundle exec rake db:create db:migrate
[email protected] ADMIN_PASSWORD=password rake admin:create_user
popd
ADMIN_EMAIL="$ADMIN_USER" ADMIN_PASSWORD="$ADMIN_PASS" rake admin:create_user
popd >/dev/null

if [[ " $* " == *' --real-auth ' ]]; then
echo "Using real authentication; set google_oauth_client_id in config.js to use Google auth";
unset USE_MOCK_GOOGLE
else
export USE_MOCK_GOOGLE=true
fi

if [[ -n "$USE_MOCK_GOOGLE" ]]; then
echo "Using mock google authentication server (specify --real-auth to use real auth)";
export GOOGLE_AUTH_ENDPOINT=https://localhost:3100/auth
npm --prefix="$BASE_DIR/mock-google-server" start & PID_MGS=$!
EXIT_SCRIPT="$EXIT_SCRIPT kill $PID_MGS || true;";
fi

pushd "$BASE_DIR/api" >/dev/null
bundle exec rails server -b 0.0.0.0 -p 4000 & PID_API=$!
EXIT_SCRIPT="$EXIT_SCRIPT kill $PID_API || true;";
popd >/dev/null

echo;
echo "Created admin user '$ADMIN_USER' with password '$ADMIN_PASS'"
echo "Log in to https://localhost:4000/admin to administer"
echo "App will be available at https://localhost:3000/"
echo "Press Ctrl+C to stop"

pushd web
gulp local-run
popd
# react-scripts clears console history so the above message disappears :(
npm --prefix="$BASE_DIR/web" start
11 changes: 8 additions & 3 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

set -e

# API Unit Tests
pushd api
bundle exec rake db:create db:migrate
bundle exec rake
popd

pushd web
gulp spec-app
gulp local-acceptance
# Frontend Unit Tests
CI=true npm --prefix=web test

# E2E Tests
export USE_MOCK_GOOGLE=true
pushd e2e
bundle exec rspec
popd
28 changes: 7 additions & 21 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"pivotal-js-jasmine-matchers": "^0.1.1"
},
"scripts": {
"start": "react-scripts start",
"start": "REACT_APP_USE_MOCK_GOOGLE=$USE_MOCK_GOOGLE react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
Expand Down
3 changes: 2 additions & 1 deletion web/src/components/google_login_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ export default class GoogleLoginWrapper extends React.Component {
handleClickCapture(event) {
if (global.Retro.config.mock_google_auth) {
event.stopPropagation();
const mockedEmail = window.mock_google_auth.split('_')[1];
this.props.onSuccess({
profileObj: {
email: 'my-email@example.com',
email: mockedEmail + '@example.com',
name: 'my full name'
},
accessToken: window.mock_google_auth
Expand Down
9 changes: 9 additions & 0 deletions web/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ import * as serviceWorker from './serviceWorker';
// TODO: polyfills?

const {config} = global.Retro;

if (process.env.REACT_APP_USE_MOCK_GOOGLE) {
config.mock_google_auth = true;
config.google_oauth_client_id = null;
window.mock_google_auth = 'expected-valid-access-token_manual-testing';
} else if (process.env.REACT_APP_GOOGLE_OAUTH_CLIENT_ID) {
config.google_oauth_client_id = process.env.REACT_APP_GOOGLE_OAUTH_CLIENT_ID;
}

window.Retro = {config};

ReactDOM.render(<EnhancedApplication {...{config}}/>, document.getElementById('root'));
Expand Down

0 comments on commit c21d9f2

Please sign in to comment.