Skip to content

Commit

Permalink
ci: adds basic e2e tests (#446)
Browse files Browse the repository at this point in the history
* chore: add basic e2e tests

* chore: update e2e tests to use fixed time in the day

* chore: remove unnecessary snapshots
  • Loading branch information
eh-am committed Oct 8, 2021
1 parent 29781f8 commit 2fd51d1
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cypress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ It requires docker installed and available under the `docker` binary in `PATH`.

To just run without updating the snapshots, run
```
CYPRESS_updateSnapshots=false yarn cy:ss
yarn cy:ss-check
```

## Why
Expand Down
74 changes: 67 additions & 7 deletions cypress/integration/e2e.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,79 @@
// Following tests should have NO mocking involved.
// The objective involve validating server/webapp interaction is working correctly
// Therefore we can't really validate certain states
//
// TODO
// somehow seed the database?
import { v4 as uuidv4 } from 'uuid';
import * as moment from 'moment';

describe('E2E Tests', () => {
// TODO:
// instead of generating a new application
// delete the old one?
let appName = '';
// use a fixed time IN THE DAY so that the hours in the timeline are always the same
const t0 = moment().startOf('day').unix();
const t1 = moment().startOf('day').add(3, 'minutes').unix();
const t2 = moment().startOf('day').add(5, 'minutes').unix();
const t3 = moment().startOf('day').add(6, 'minutes').unix();
const t4 = moment().startOf('day').add(10, 'minutes').unix();

before(() => {
appName = uuidv4();

// populate the db with 2 items
//
// it's important that they are recent
// otherwise the database may just drop them
// if they are older than the retention date

cy.request({
method: 'POST',
url: `/ingest?name=${appName}&sampleRate=100&from=${t1}&until=${t1}`,
body: 'foo;bar 100',
});

cy.request({
method: 'POST',
url: `/ingest?name=${appName}&sampleRate=100&from=${t3}&until=${t3}`,
body: 'foo;bar;baz 10',
});
});

it('tests single view', () => {
cy.visit('/');
cy.visit(`/?query=${appName}&from=${t0}&until=${t4}`);

cy.findByTestId('flamegraph-canvas').matchImageSnapshot(
`e2e-single-flamegraph`
);
});

it('tests /comparison view', () => {
cy.visit('/comparison');
cy.visit(
`/comparison?query=${appName}&leftFrom=${t0}&leftUntil=${t2}&rightFrom=${t2}&rightUntil=${t4}&from=${t0}&until=${t4}`
);

const findFlamegraph = (n: number) => {
const query = `> :nth-child(${n})`;

return cy.findByTestId('comparison-container').find(query);
};

// flamegraph 1 (the left one)
findFlamegraph(1)
.findByTestId('flamegraph-canvas')
.matchImageSnapshot(`e2e-comparison-flamegraph-left`);

// flamegraph 2 (the right one)
findFlamegraph(2)
.findByTestId('flamegraph-canvas')
.matchImageSnapshot(`e2e-comparison-flamegraph-right`);
});

it('tests /comparison-diff view', () => {
cy.visit('/comparison-diff');
cy.visit(
`/comparison-diff?query=${appName}&from=${t2}&until=${t4}&leftFrom=${t0}&leftUntil=${t2}`
);

cy.findByTestId('flamegraph-canvas').matchImageSnapshot(
`e2e-comparison-diff-flamegraph`
);
});
});
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"cy:open": "cypress open",
"cy:ci": "cypress run",
"cy:ss": "./scripts/cypress-screenshots.sh",
"cy:ss-check": "CYPRESS_updateSnapshots=false ./scripts/cypress-screenshots.sh",
"prepare": "husky install",
"lint-staged": "lint-staged"
},
Expand Down Expand Up @@ -80,6 +81,7 @@
"sync-request": "^6.1.0",
"ts-jest": "^27.0.5",
"typescript": "^4.4.3",
"uuid": "^8.3.2",
"webpack": "~5.51.1",
"webpack-bundle-analyzer": "^4.4.2",
"webpack-cli": "^4.8.0",
Expand Down

0 comments on commit 2fd51d1

Please sign in to comment.