Skip to content

Commit 09e13ef

Browse files
committed
Add angular e2e testing
1 parent 52d1e47 commit 09e13ef

File tree

6 files changed

+124
-10
lines changed

6 files changed

+124
-10
lines changed

.eslintrc.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,16 @@ module.exports = {
4242
es2020: true,
4343
'jest/globals': true,
4444
node: true,
45+
jasmine: true,
4546
},
4647
globals: {
4748
instantsearch: true,
4849
instantMeiliSearch: true,
49-
page: true, // for jest/puppeteer tests in examples/express
50-
browser: true, // for jest/puppeteer tests in examples/express
51-
context: true, // for jest/puppeteer tests in examples/express
52-
jestPuppeteer: true, // for jest/puppeteer tests in examples/express
50+
page: true, // for jest/puppeteer tests in tests/env/express
51+
browser: true, // for jest/puppeteer tests in tests/env/express
52+
context: true, // for jest/puppeteer tests in tests/env/express
53+
jestPuppeteer: true, // for jest/puppeteer tests in tests/env/express
54+
jasmine: true, // for angular e2e tests in playground/angular
5355
},
5456
extends: [
5557
'standard',
@@ -100,12 +102,14 @@ module.exports = {
100102
browser: true,
101103
es2020: true,
102104
'jest/globals': true,
105+
jasmine: true,
103106
},
104107
globals: {
105-
page: true, // for jest/puppeteer tests in examples/express
106-
browser: true, // for jest/puppeteer tests in examples/express
107-
context: true, // for jest/puppeteer tests in examples/express
108-
jestPuppeteer: true, // for jest/puppeteer tests in examples/express
108+
page: true, // for jest/puppeteer tests in tests/env/express
109+
browser: true, // for jest/puppeteer tests in tests/env/express
110+
context: true, // for jest/puppeteer tests in tests/env/express
111+
jestPuppeteer: true, // for jest/puppeteer tests in tests/env/express
112+
jasmine: true, // for angular e2e tests in playground/angular
109113
},
110114
extends: [
111115
'standard',

jest.config.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@ module.exports = {
77
// We are using jest-environment-jsdom 25 until we stop supporting node 10
88
// jest-environment-jsdom 25 uses jsdom 15 which still supports node 10
99
testEnvironment: 'jest-environment-jsdom',
10-
testPathIgnorePatterns: ['<rootDir>/tests/env/express'],
10+
testPathIgnorePatterns: [
11+
'<rootDir>/tests/env/express',
12+
'<rootDir>/playgrounds/angular',
13+
],
1114
},
1215
{
1316
preset: 'ts-jest',
1417
displayName: 'node',
1518
testEnvironment: 'node',
16-
testPathIgnorePatterns: ['<rootDir>/tests/env/express'],
19+
testPathIgnorePatterns: [
20+
'<rootDir>/tests/env/express',
21+
'<rootDir>/playgrounds/angular',
22+
],
1723
},
1824
],
1925
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// @ts-check
2+
// Protractor configuration file, see link for more information
3+
// https://github.com/angular/protractor/blob/master/lib/config.ts
4+
5+
const { SpecReporter, StacktraceOption } = require('jasmine-spec-reporter')
6+
7+
/**
8+
* @type { import("protractor").Config }
9+
*/
10+
exports.config = {
11+
allScriptsTimeout: 11000,
12+
specs: ['./src/**/*.e2e-spec.ts'],
13+
capabilities: {
14+
browserName: 'chrome',
15+
},
16+
directConnect: true,
17+
SELENIUM_PROMISE_MANAGER: false,
18+
baseUrl: 'http://localhost:4200/',
19+
framework: 'jasmine',
20+
jasmineNodeOpts: {
21+
showColors: true,
22+
defaultTimeoutInterval: 30000,
23+
print: function () {},
24+
},
25+
onPrepare() {
26+
require('ts-node').register({
27+
project: require('path').join(__dirname, './tsconfig.json'),
28+
})
29+
jasmine.getEnv().addReporter(
30+
new SpecReporter({
31+
spec: {
32+
displayStacktrace: StacktraceOption.PRETTY,
33+
},
34+
})
35+
)
36+
},
37+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { browser, logging } from 'protractor'
2+
import { AppPage } from './app.po'
3+
4+
describe('workspace-project App', () => {
5+
let page: AppPage
6+
7+
beforeEach(() => {
8+
page = new AppPage()
9+
})
10+
11+
it('First game should be counter strike', async () => {
12+
await page.navigateTo()
13+
expect(await page.getFirstGame()).toEqual('Counter-Strike')
14+
})
15+
16+
it('First facet value of first facet should be Action', async () => {
17+
await page.navigateTo()
18+
expect(await page.getFirstFacetValueOfFirstFacet()).toEqual('Action')
19+
})
20+
21+
it('Clear refinement should exist', async () => {
22+
await page.navigateTo()
23+
expect(await page.getClearRefinementText()).toEqual('Clear refinements')
24+
})
25+
26+
afterEach(async () => {
27+
// Assert that there are no errors emitted from the browser
28+
const logs = await browser.manage().logs().get(logging.Type.BROWSER)
29+
expect(logs).not.toContain(
30+
jasmine.objectContaining({
31+
level: logging.Level.SEVERE,
32+
} as logging.Entry)
33+
)
34+
})
35+
})
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { browser, by, element } from 'protractor'
2+
3+
export class AppPage {
4+
async navigateTo(): Promise<unknown> {
5+
return browser.get(browser.baseUrl)
6+
}
7+
8+
async getFirstGame(): Promise<string> {
9+
return element(by.css('.ais-Hits-item:first-child > .hit-name')).getText()
10+
}
11+
12+
async getFirstFacetValueOfFirstFacet(): Promise<string> {
13+
return element(by.css('.ais-RefinementList-labelText')).getText()
14+
}
15+
16+
async getClearRefinementText(): Promise<string> {
17+
return element(by.css('.ais-ClearRefinements-button')).getText()
18+
}
19+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* To learn more about this file see: https://angular.io/config/tsconfig. */
2+
{
3+
"extends": "../tsconfig.json",
4+
"compilerOptions": {
5+
"outDir": "../out-tsc/e2e",
6+
"module": "commonjs",
7+
"target": "es2018",
8+
"types": [
9+
"jasmine",
10+
"node"
11+
]
12+
}
13+
}

0 commit comments

Comments
 (0)