-
Notifications
You must be signed in to change notification settings - Fork 88
chore: add e2e #789
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
Merged
Merged
chore: add e2e #789
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c3bc7cd
chore: move cypress out of demo
8ca0d67
Update package.json
f888462
chore: add ci specific config
f537dc4
chore: fix testing library support
fed6aa2
chore: fix config file location
0136ae8
chore: add data-testid for the lists
c04b618
chore: change site to stub api request on dev
275be49
chore: add e2e tests
c4062ab
chore: add locale test
10cce05
chore: get back actual call to shows
8c9c9a9
chore: fix test
0c0df1a
chore: update snapidoos
a9f9b86
chore: remove unused command
cd2fb17
Merge branch 'main' into tln/add-e2e
42dc3c1
Merge branch 'main' into tln/add-e2e
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* @see {@link https://nextjs.org/docs/advanced-features/custom-error-page} | ||
*/ | ||
describe('Custom error pages', () => { | ||
it('should show custom 404 page on /404', () => { | ||
cy.visit('/404', {failOnStatusCode: false}) | ||
cy.findByText('Custom 404 - Page Not Found') | ||
}) | ||
|
||
it('should show custom 500 page on /500', () => { | ||
cy.visit('/500', {failOnStatusCode: false}) | ||
cy.findByText('Custom 500 - Server-side error occurred') | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
describe('Default site', () => { | ||
beforeEach(() => { | ||
cy.visit('/') | ||
}) | ||
|
||
it('loads home page', () => { | ||
cy.findByText('Next Demo!') | ||
cy.findByTestId("list-server-side").within(() => { | ||
cy.findAllByRole("link").should('have.length', 5) | ||
}) | ||
|
||
cy.findByTestId("list-dynamic-pages").within(() => { | ||
cy.findAllByRole("link").should('have.length', 3) | ||
}) | ||
|
||
cy.findByTestId("list-catch-all").within(() => { | ||
cy.findAllByRole("link").should('have.length', 3) | ||
}) | ||
|
||
cy.findByTestId("list-static").within(() => { | ||
cy.findAllByRole("link").should('have.length', 2) | ||
}) | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
describe('Dynamic Routing', () => { | ||
it('loads page', () => { | ||
cy.visit('/shows/250') | ||
cy.findByRole('heading').should('contain', '250') | ||
cy.findByText('Kirby Buckets') | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
describe('Headers', () => { | ||
it('should set headers from the next.config.js', () => { | ||
cy.request({ | ||
url: '/', | ||
}).then((response) => { | ||
expect(response.headers).to.have.property('x-custom-header', 'my custom header value') | ||
}) | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
describe('Localization', () => { | ||
it('should use sub routing to determine current locale', () => { | ||
cy.visit('/'); | ||
|
||
cy.findByText('The current locale is en') | ||
|
||
cy.visit('/fr') | ||
cy.findByText('The current locale is fr') | ||
}) | ||
|
||
it('should use the NEXT_LOCALE cookie to determine the default locale', () => { | ||
cy.setCookie('NEXT_LOCALE', 'fr') | ||
cy.visit('/'); | ||
|
||
cy.findByText('The current locale is fr') | ||
}) | ||
|
||
it('should use the NEXT_LOCALE cookie over Accept-Language header to determine the default locale', () => { | ||
// cy.setCookie('NEXT_LOCALE', 'en') | ||
cy.visit({ | ||
url: '/', | ||
headers: { | ||
'Accept-Language': 'fr;q=0.9' | ||
} | ||
}); | ||
cy.findByText('The current locale is fr') | ||
|
||
cy.setCookie('NEXT_LOCALE', 'en') | ||
cy.visit({ | ||
url: '/', | ||
headers: { | ||
'Accept-Language': 'fr;q=0.9' | ||
} | ||
}); | ||
|
||
cy.findByText('The current locale is en') | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* @see {@link https://nextjs.org/docs/api-reference/next/image#required-props} | ||
*/ | ||
describe('next/images', () => { | ||
it('should show static image from /public', () => { | ||
cy.visit('/') | ||
cy.findByRole('img').should('be.visible').and(($img) => { | ||
// "naturalWidth" and "naturalHeight" are set when the image loads | ||
expect( | ||
$img[0].naturalWidth, | ||
'image has natural width' | ||
).to.be.greaterThan(0) | ||
}) | ||
}) | ||
|
||
it('should show image using next/image', () => { | ||
cy.visit('/image') | ||
cy.findByRole('img', { name: /shiba inu dog looks through a window/i }) | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
describe('Preview Mode', () => { | ||
it('enters and exits preview mode', () => { | ||
// preview mode is off by default | ||
cy.visit('/previewTest') | ||
cy.findByText('Number: 4') | ||
|
||
// enter preview mode | ||
cy.request('/api/enterPreview').then( | ||
(response) => { | ||
expect(response.body).to.have.property('name', 'preview mode') | ||
} | ||
) | ||
cy.visit('/previewTest') | ||
cy.findByText('Number: 3') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My preview mode PR changes the text here, so this will need an update |
||
|
||
// exit preview mode | ||
cy.request('/api/exitPreview') | ||
cy.visit('/previewTest') | ||
cy.findByText('Number: 4') | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
describe('Rewrites and Redirects', () => { | ||
it('rewrites: points /old to /', () => { | ||
// preview mode is off by default | ||
cy.visit('/old') | ||
cy.findByText('Next Demo!') | ||
cy.url().should('eq', `${Cypress.config().baseUrl}/old/`) | ||
|
||
// ensure headers are still set | ||
cy.request('/api/enterPreview').then( | ||
(response) => { | ||
expect(response.body).to.have.property('name', 'preview mode') | ||
} | ||
) | ||
}) | ||
|
||
it('redirects: redirects /redirectme to /', () => { | ||
cy.visit('/redirectme') | ||
cy.url().should('eq', `${Cypress.config().baseUrl}/`) | ||
} | ||
) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
describe('Trailing slash enabled', () => { | ||
it('should keep the trailing slash, i.e. points /old/ to /old/', () => { | ||
cy.visit('/old/') | ||
cy.url().should('eq', `${Cypress.config().baseUrl}/old/`) | ||
}) | ||
|
||
it('should put a trailing slash when there is none, i.e. points /old to /old/', () => { | ||
cy.visit('/old') | ||
cy.url().should('eq', `${Cypress.config().baseUrl}/old/`) | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,23 @@ module.exports = { | |
defaultLocale: 'en', | ||
locales: ['en', 'es', 'fr'] | ||
}, | ||
// trailingSlash: true, | ||
async headers() { | ||
return [ | ||
{ | ||
source: '/', | ||
headers: [ | ||
{ | ||
key: 'x-custom-header', | ||
value: 'my custom header value', | ||
} | ||
], | ||
}, | ||
] | ||
}, | ||
trailingSlash: true, | ||
// Configurable site features _to_ support: | ||
// basePath: '/docs', | ||
// Rewrites allow you to map an incoming request path to a different destination path. | ||
async rewrites() { | ||
return { | ||
beforeFiles: [ | ||
|
@@ -18,5 +32,15 @@ module.exports = { | |
} | ||
] | ||
} | ||
} | ||
}, | ||
// Redirects allow you to redirect an incoming request path to a different destination path. | ||
async redirects() { | ||
return [ | ||
{ | ||
source: '/redirectme', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not one for this PR, but adding a regex-based rewrite would be good |
||
destination: '/', | ||
permanent: true, | ||
}, | ||
] | ||
}, | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this check if the image actually loads?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, I'll add the same width/height as the other image test