Skip to content

Commit

Permalink
test: e2e tests, docker and playwright config + linting and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Leighton authored and zleight1 committed Mar 4, 2021
1 parent c709fa1 commit 8e5d642
Show file tree
Hide file tree
Showing 8 changed files with 9,156 additions and 4,525 deletions.
15 changes: 15 additions & 0 deletions Dockerfile.e2e
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Prebuilt MS image
FROM mcr.microsoft.com/playwright:bionic

WORKDIR /app

COPY package.json package-lock.json ./

RUN npm ci

COPY . .

RUN npm run build

# Run the npm run test:e2e command to host the server and run the e2e tests
CMD ["npm", "run", "test:e2e"]
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,22 @@ npm run build
npm run lint
```

### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/).
### Runs e2e tests
```
npm run test:e2e
```

## Docker commands

### Hosting the app

```
docker build . -t arthur
docker run -p 9000:8080 arthur
```

### Running the e2e tests
```
docker build . -f Dockerfile.e2e -t arthur-e2e
docker run --rm arthur-e2e
```
5 changes: 5 additions & 0 deletions __tests__/e2e/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
extends: [
'plugin:jest-playwright/recommended'
]
};
43 changes: 43 additions & 0 deletions __tests__/e2e/arthur.e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
describe('arthur', () => {
beforeEach(async () => {
await page.goto('http://localhost:8080/')
})

test('should show the page with buttons and initial state', async () => {
await expect(page).toHaveText("#dog-message", "I'm waiting...");
await expect(page).toHaveText("#bone-count", "Current bone count: 0");
});

test('should count up and woof when a bone is given', async () => {
await page.click("#give-bone");
await expect(page).toHaveText("#dog-message", "Woof!");
await expect(page).toHaveText("#bone-count", "Current bone count: 1");

});

test('should count down and whine when a bone is taken', async () => {
await page.click("#give-bone");
await page.click("#give-bone");
// first give 2 bones so we have bones to take!
await expect(page).toHaveText("#dog-message", "Woof!");
await expect(page).toHaveText("#bone-count", "Current bone count: 2");


await page.click("#take-bone");

await expect(page).toHaveText("#dog-message", "Whine!");
await expect(page).toHaveText("#bone-count", "Current bone count: 1");

});

test('should be confused when a bone is taken and the count is zero', async () => {
// check it's 0 first
await expect(page).toHaveText("#dog-message", "I'm waiting...");
await expect(page).toHaveText("#bone-count", "Current bone count: 0");

await page.click("#take-bone");

await expect(page).toHaveText("#dog-message", "I'm confused!");
await expect(page).toHaveText("#bone-count", "Current bone count: 0");
});
})
13 changes: 13 additions & 0 deletions jest-playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// jest-playwright.config.js

module.exports = {
browsers: ['chromium', 'webkit', 'firefox'],
serverOptions: {
command: 'npm run start',
port: 8080,
usedPortAction: 'kill',
waitOnScheme: {
delay: 1000,
}
}
}
5 changes: 5 additions & 0 deletions jest.e2e.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
preset: 'jest-playwright-preset',
setupFilesAfterEnv: ['expect-playwright'],
testMatch: ['**/*.e2e.js']
};
Loading

0 comments on commit 8e5d642

Please sign in to comment.