Skip to content

Instantly share code, notes, and snippets.

⏺ I've found the root cause. Here's the full diagnosis:
---
Root Cause: Middleware is in the wrong location
The middleware file is at app/middleware.ts but Next.js requires it at the project root (middleware.ts).
Because of this, the middleware never runs. This is confirmed by both Replay recordings:
<body>
  <style>/* Hey, I’m a style tag */</style>
  <script>// Hello, I’m a script</script>
</body>
cy.contains('Hey, I’m a style tag'); // will not select <style> in v9
cy.contains('Hello, I’m a script'); // will not select 
@filiphric
filiphric / contains.js
Last active November 18, 2021 22:12
cy.contains() comand
// selects any element with the text "Dashboard"
cy.contains('Dashboard')
// selects a h1 element with the text "Dashboard"
cy.contains('h1', 'Dashboard')
@filiphric
filiphric / spec.ts
Created October 12, 2021 20:39
Changing user agent in cy.visit() command
it('changing user agent', () => {
cy.visit('/', {
onBeforeLoad: (win) => {
Object.defineProperty(win.navigator, 'userAgent', {
value: 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
});
}
})
})
@filiphric
filiphric / cypress.json
Created October 12, 2021 20:35
Changing user agent in cypress.json
{
"userAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1"
}
@filiphric
filiphric / spec.ts
Last active October 12, 2021 20:39
Viewing an app on touch device
it('touch device', () => {
cy.visit('/', {
onBeforeLoad: (win) => {
win.ontouchstart = true
}
})
})
@filiphric
filiphric / spec.ts
Last active October 12, 2021 19:32
Using cy.viewport() command to test different resolutions
it('viewport test', () => {
cy.visit('/')
cy.viewport(320, 480)
cy.viewport('iphone-5')
});
@filiphric
filiphric / index.js
Created February 1, 2021 23:38
Login page object
const app = new Vue({
// ...
}).$mount('#trello-app');
window.app = app;
beforeEach( function() {
window.logCalls = 1;
window.testFlow = [];
});
Cypress.Commands.overwrite('log', (originalFn, message) => {
Cypress.log({
displayName: `--- ${window.logCalls}. ${message} ---`,
name: `--- ${window.logCalls}. ${message} ---`,
beforeEach( function() {
window.logCalls = 1;
});
Cypress.Commands.overwrite('log', (originalFn, message) => {
Cypress.log({
displayName: `--- ${window.logCalls}. ${message} ---`,
name: `--- ${window.logCalls}. ${message} ---`,
message: ''