Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add e2e smoke tests for headless-ssr utils #3093

Merged
merged 85 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
aa7b479
setup ssr sub-package
mrrajamanickam-coveo Jul 19, 2023
7d641ea
wip: add define search engine and related types
mrrajamanickam-coveo Jul 20, 2023
e34bb98
copy more type defs from benjamin's branch
mrrajamanickam-coveo Jul 21, 2023
8ceba61
specify node version to fix eslint errors reg unsupported node features
mrrajamanickam-coveo Jul 24, 2023
6c93b55
complete copying over all required types
mrrajamanickam-coveo Jul 24, 2023
1095cb6
rename couple of types to match underlying names
mrrajamanickam-coveo Jul 24, 2023
d268ef8
reorder types based on usage
mrrajamanickam-coveo Jul 25, 2023
19c4196
add headless ssr import path to atomic dev build
mrrajamanickam-coveo Jul 26, 2023
d99eec7
add nextjs app for headless ssr example
mrrajamanickam-coveo Jul 26, 2023
386c48c
trim generated files to simplify
mrrajamanickam-coveo Jul 26, 2023
650e727
add headless as dep
mrrajamanickam-coveo Jul 27, 2023
d5953cf
export define search engine from headless ssr
mrrajamanickam-coveo Jul 27, 2023
256aaab
remove async from hydrate as it can't be used with CSR
mrrajamanickam-coveo Jul 27, 2023
9df4e40
add sample page using headless ssr utils
mrrajamanickam-coveo Jul 27, 2023
2b204fa
simplify result list render, move engine to common dir
mrrajamanickam-coveo Jul 27, 2023
988a8fb
fix no-async-promise-executor eslint error
mrrajamanickam-coveo Jul 27, 2023
b1883df
update todos
mrrajamanickam-coveo Jul 27, 2023
8645829
Revert "remove async from hydrate as it can't be used with CSR"
mrrajamanickam-coveo Jul 28, 2023
1cdb098
render sample with async hydrate
mrrajamanickam-coveo Jul 28, 2023
93a526e
add unit tests
mrrajamanickam-coveo Jul 28, 2023
63dfc4c
Fix headless isExpiredTokenError (KIT-2620)
mrrajamanickam-coveo Jul 29, 2023
a5a9ca9
add test for results
mrrajamanickam-coveo Jul 29, 2023
a790cf6
update comments
mrrajamanickam-coveo Jul 29, 2023
6f2251a
update name, desc of sample pkg
mrrajamanickam-coveo Jul 29, 2023
8b674c4
Merge branch 'master' into KIT-2600_headless_ssr_init
mrrajamanickam-coveo Jul 29, 2023
a0f669b
add a project json to headless ssr pkg
mrrajamanickam-coveo Jul 31, 2023
943dc5e
update headless
mrrajamanickam-coveo Jul 31, 2023
3d39816
remove pkg lock
mrrajamanickam-coveo Jul 31, 2023
4d1fd71
regen root pkg lock
mrrajamanickam-coveo Jul 31, 2023
86cc1d2
Revert "add headless ssr import path to atomic dev build"
mrrajamanickam-coveo Jul 31, 2023
0b88358
pkg json update after build
mrrajamanickam-coveo Jul 31, 2023
0320873
reorg files under /src/
mrrajamanickam-coveo Jul 31, 2023
aef34c3
add root to eslint config
mrrajamanickam-coveo Jul 31, 2023
5f52560
fix dep list for effect
mrrajamanickam-coveo Aug 1, 2023
ea77d6b
use suspense when loading
mrrajamanickam-coveo Aug 1, 2023
4929ef1
use any action type from redux
mrrajamanickam-coveo Aug 1, 2023
bdbbe5d
add eslint config to ignore unused vars/args starting with underscore
mrrajamanickam-coveo Aug 1, 2023
c565d9a
Merge branch 'master' into KIT-2600_headless_ssr_init
mrrajamanickam-coveo Aug 1, 2023
57b0ec3
mark exports as @internal
mrrajamanickam-coveo Aug 1, 2023
c52fe71
split types into smaller files
mrrajamanickam-coveo Aug 1, 2023
86c4f11
split types part 2
mrrajamanickam-coveo Aug 1, 2023
cc5ebde
change internal tag to beta
mrrajamanickam-coveo Aug 1, 2023
dc7b6fb
move map obj to utils file
mrrajamanickam-coveo Aug 1, 2023
d177d02
move type files under a types/ dir
mrrajamanickam-coveo Aug 1, 2023
5231524
split types part 3
mrrajamanickam-coveo Aug 2, 2023
e5da018
add loading page for automatic suspense
mrrajamanickam-coveo Aug 2, 2023
ff51a68
remove loading cmp
mrrajamanickam-coveo Aug 2, 2023
cac4812
render results directly
mrrajamanickam-coveo Aug 2, 2023
1a78318
rename initial state in controller snapshot to remove redundancy/conf…
mrrajamanickam-coveo Aug 2, 2023
168d5d6
add custom controller to fetch results from snapshot
mrrajamanickam-coveo Aug 2, 2023
2e71812
mark SSR exported members as @internal
mrrajamanickam-coveo Aug 2, 2023
2f84eeb
move map object into headless utils
mrrajamanickam-coveo Aug 2, 2023
da89e68
move search engine types to its own file
mrrajamanickam-coveo Aug 2, 2023
5f5715c
rename to remove redundant suffix from type files
mrrajamanickam-coveo Aug 2, 2023
da62a01
add new line
mrrajamanickam-coveo Aug 2, 2023
4c1dc78
Merge branch 'master' into KIT-2600_headless_ssr_init
mrrajamanickam-coveo Aug 2, 2023
7348ac2
update pkg lock
mrrajamanickam-coveo Aug 2, 2023
fcc6b79
rename snapshot to initial state
mrrajamanickam-coveo Aug 3, 2023
12a9f11
fix eslint no async promise executor
mrrajamanickam-coveo Aug 3, 2023
be680fc
Merge branch 'master' into KIT-2600_headless_ssr_init
mrrajamanickam-coveo Aug 3, 2023
0005ea8
add cypress
mrrajamanickam-coveo Aug 4, 2023
e504865
add csr smoke test
mrrajamanickam-coveo Aug 4, 2023
fdcc886
add web vitals check
mrrajamanickam-coveo Aug 4, 2023
8d449e9
add gh action for e2e
mrrajamanickam-coveo Aug 4, 2023
1acb1aa
add base url config
mrrajamanickam-coveo Aug 4, 2023
e31e57b
add specific vitals thresholds based on current stats
mrrajamanickam-coveo Aug 4, 2023
644c3e2
add timestamp to rendered results
mrrajamanickam-coveo Aug 4, 2023
7b8dcaf
add ssr smoke test
mrrajamanickam-coveo Aug 4, 2023
3c4355d
add test
mrrajamanickam-coveo Aug 4, 2023
bed7d5f
add note
mrrajamanickam-coveo Aug 5, 2023
10b27ac
Merge branch 'master' into KIT-2643_e2e_headless_ssr
mrrajamanickam-coveo Aug 8, 2023
ab0e463
add span for hydrated msg
mrrajamanickam-coveo Aug 8, 2023
9571a42
Merge branch 'master' into KIT-2643_e2e_headless_ssr
mrrajamanickam-coveo Aug 8, 2023
cba2d7a
modify web vitals thresholds to accommodate CI env
mrrajamanickam-coveo Aug 8, 2023
5377992
remove unused autogenerated file
mrrajamanickam-coveo Aug 10, 2023
b78ef41
Merge branch 'master' into KIT-2643_e2e_headless_ssr
mrrajamanickam-coveo Aug 10, 2023
5f08f50
remove autogenerated unused e2e file
mrrajamanickam-coveo Aug 10, 2023
b32aa2c
add cypress config to disable support file
mrrajamanickam-coveo Aug 10, 2023
9c91ccf
update cypress to v12 and update other deps as well
mrrajamanickam-coveo Aug 10, 2023
db4316b
update test to work with cy12, turn off video
mrrajamanickam-coveo Aug 10, 2023
d92fb2c
ci: add next cache, enable cy install
mrrajamanickam-coveo Aug 10, 2023
3c0cea9
revert next to previous patch version
mrrajamanickam-coveo Aug 10, 2023
485eab7
ci: remove next cache
mrrajamanickam-coveo Aug 10, 2023
a31ed6f
use project instead of working dir
mrrajamanickam-coveo Aug 11, 2023
36bec14
revert to using working dir with install false
mrrajamanickam-coveo Aug 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/actions/e2e-headless-ssr/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: 'Headless SSR E2E tests'
description: 'Runs Cypress tests for Headless SSR'
inputs:
github-token:
description: The GitHub token for accurately detecting a build vs a re-run build
required: false
default: ''
runs:
using: composite
steps:
- uses: cypress-io/github-action@v5
name: Run Cypress
with:
browser: chrome
command-prefix: 'npx cypress-repeat run -n 3 --until-passes --rerun-failed-only --'
working-directory: ./packages/samples/headless-ssr
start: npm run prod
wait-on: 'http://localhost:3000'
install: false
record: false

- uses: actions/upload-artifact@v3
if: failure()
with:
name: cypress-screenshots
path: packages/samples/headless-ssr/cypress/screenshots
11 changes: 10 additions & 1 deletion .github/workflows/prbot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ jobs:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup
- uses: ./.github/actions/e2e-atomic-insight-panel
e2e-headless-ssr-test:
name: 'Run e2e tests on Headless SSR sample'
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup
- uses: ./.github/actions/e2e-headless-ssr
e2e-quantic-setup:
name: 'Setup e2e tests on Quantic'
needs: build
Expand All @@ -152,7 +160,8 @@ jobs:
strategy:
fail-fast: false
matrix:
spec: [
spec:
[
'cypress/e2e/default-1/**/*',
'cypress/e2e/default-2/**/*',
'cypress/e2e/facets-1/**/*',
Expand Down
56 changes: 45 additions & 11 deletions package-lock.json

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

7 changes: 7 additions & 0 deletions packages/samples/headless-ssr/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {defineConfig} from 'cypress';

export default defineConfig({
e2e: {
baseUrl: 'http://localhost:3000/',
},
});
56 changes: 56 additions & 0 deletions packages/samples/headless-ssr/cypress/e2e/ssr.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import 'cypress-web-vitals';

describe('headless ssr example', () => {
const numResults = 10;
const numResultsMsg = `Hydrated engine with ${numResults} results`;
const msgSelector = '#hydrated-msg';
const timestampSelector = '#timestamp';
it('renders page in SSR as expected', () => {
cy.intercept('/', (req) => {
req.continue((resp) => {
const dom = new DOMParser().parseFromString(resp.body, 'text/html');
expect(dom.querySelector(msgSelector)?.textContent).to.equal(
numResultsMsg
);
expect(dom.querySelectorAll('li').length).to.equal(numResults);
});
});
cy.visit('/');
});

it('renders page in CSR as expected', () => {
cy.visit('/');
cy.get(msgSelector).should('have.text', numResultsMsg);
cy.get('li').should('have.length', numResults);
});

it('renders result list in SSR and then in CSR', () => {
const interceptAlias = 'searchResults';
cy.intercept('/').as(interceptAlias);

cy.visit('/');
cy.wait(`@${interceptAlias}`).then((intercept) => {
mrrajamanickam-coveo marked this conversation as resolved.
Show resolved Hide resolved
const dom = new DOMParser().parseFromString(
intercept.response?.body,
'text/html'
);
const ssrTimestamp = Date.parse(
dom.querySelector(timestampSelector)!.innerHTML
);
expect(ssrTimestamp).to.not.be.undefined;
cy.get(timestampSelector).should((timeStampElement) => {
const csrTimestamp = Date.parse(timeStampElement.text());
expect(csrTimestamp).to.be.greaterThan(ssrTimestamp);
});
});
});

it('should pass the web-vitals audits', () => {
mrrajamanickam-coveo marked this conversation as resolved.
Show resolved Hide resolved
// TODO: Add input based vitals after interactive elements are added to test page (e.g. search box)
// Note: Thresholds might need to be adjusted as the page tested changes (e.g. more components are added etc)
const VITALS_THRESHOLD = {
thresholds: {fcp: 100, lcp: 100, cls: 0, ttfb: 20},
};
cy.vitals(VITALS_THRESHOLD);
});
});
37 changes: 37 additions & 0 deletions packages/samples/headless-ssr/cypress/support/commands.ts
mrrajamanickam-coveo marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/// <reference types="cypress" />
// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }
20 changes: 20 additions & 0 deletions packages/samples/headless-ssr/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
8 changes: 7 additions & 1 deletion packages/samples/headless-ssr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
"lint": "next lint",
"prod": "npm run build && npm run start",
"e2e": "cypress run --browser chrome --e2e"
},
"dependencies": {
"@coveo/headless": "2.24.0",
Expand All @@ -20,5 +22,9 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"typescript": "5.1.6"
},
"devDependencies": {
"cypress": "10.8.0",
"cypress-web-vitals": "4.0.1"
}
}
10 changes: 9 additions & 1 deletion packages/samples/headless-ssr/src/components/result-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@ import {Result} from '@coveo/headless';
export default function ResultList({results}: {results: Result[]}) {
return (
<div>
Hydrated engine with {results?.length} results
<span id="hydrated-msg">
Hydrated engine with {results?.length} results
</span>
<ul>
{results?.map((result) => (
<li key={result.uniqueId}>
<a href={result.clickUri}>{result.title}</a>
</li>
))}
</ul>
<div>
Rendered on{' '}
<span id="timestamp" suppressHydrationWarning>
{new Date().toISOString()}
</span>
</div>
</div>
);
}
9 changes: 8 additions & 1 deletion packages/samples/headless-ssr/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,12 @@
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
"exclude": ["node_modules"],
"ts-node": {
// For Cypress https://github.com/cypress-io/cypress/issues/27448
"compilerOptions": {
"module": "es2015",
"moduleResolution": "node"
}
}
}