Skip to content

Commit c68db97

Browse files
committed
Merge branch 'main' into mk/edge-router
2 parents 9723f6c + 3b42825 commit c68db97

36 files changed

+1627
-919
lines changed

.eslintignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ node_modules
33
test
44
lib
55
demos
6-
plugin/src/templates/edge
6+
plugin/src/templates/edge
7+
plugin/lib
8+
plugin/dist-types
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Run e2e (middleware demo)
2+
on:
3+
pull_request:
4+
types: [opened, labeled, unlabeled, synchronize]
5+
push:
6+
branches:
7+
- main
8+
paths:
9+
- 'demos/middleware/**/*.{js,jsx,ts,tsx}'
10+
- 'cypress/integration/middleware/**/*.{ts,js}'
11+
- 'src/**/*.{ts,js}'
12+
jobs:
13+
cypress:
14+
name: Cypress
15+
runs-on: ubuntu-latest
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
containers: [1, 2, 3, 4]
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v2
23+
24+
- name: Generate Github token
25+
uses: navikt/github-app-token-generator@v1
26+
id: get-token
27+
with:
28+
private-key: ${{ secrets.TOKENS_PRIVATE_KEY }}
29+
app-id: ${{ secrets.TOKENS_APP_ID }}
30+
31+
- name: Checkout @netlify/wait-for-deploy-action
32+
uses: actions/checkout@v2
33+
with:
34+
repository: netlify/wait-for-deploy-action
35+
token: ${{ steps.get-token.outputs.token }}
36+
path: ./.github/actions/wait-for-netlify-deploy
37+
38+
- name: Wait for Netlify Deploy
39+
id: deploy
40+
uses: ./.github/actions/wait-for-netlify-deploy
41+
with:
42+
site-name: next-plugin-edge-middleware
43+
timeout: 300
44+
45+
- name: Deploy successful
46+
if: ${{ steps.deploy.outputs.origin-url }}
47+
run: echo ${{ steps.deploy.outputs.origin-url }}
48+
49+
- name: Node
50+
uses: actions/setup-node@v2
51+
with:
52+
node-version: '16'
53+
54+
- run: npm install
55+
56+
- name: Cypress run
57+
if: ${{ steps.deploy.outputs.origin-url }}
58+
id: cypress
59+
uses: cypress-io/github-action@v2
60+
with:
61+
browser: chrome
62+
headless: true
63+
record: true
64+
parallel: true
65+
config-file: cypress/config/middleware.json
66+
group: 'Next Plugin - Middleware'
67+
spec: cypress/integration/middleware/*
68+
env:
69+
DEBUG: '@cypress/github-action'
70+
CYPRESS_baseUrl: ${{ steps.deploy.outputs.origin-url }}
71+
CYPRESS_NETLIFY_CONTEXT: ${{ steps.deploy.outputs.context }}
72+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73+
CYPRESS_RECORD_KEY: ${{ secrets.MIDDLEWARE_CYPRESS_RECORD_KEY }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ Temporary Items
147147
demos/default/.next
148148
.parcel-cache
149149
plugin/lib
150+
plugin/dist-types
150151

151152
# Cypress
152153
cypress/screenshots

.prettierignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ lib
2222
tsconfig.json
2323
demos/nx-next-monorepo-demo
2424

25-
plugin/CHANGELOG.md
25+
plugin/CHANGELOG.md
26+
plugin/lib
27+
plugin/dist-types

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"plugin": "4.13.1"
2+
"plugin": "4.14.1"
33
}

cypress/config/middleware.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"baseUrl": "http://localhost:8888",
3+
"integrationFolder": "cypress/integration/middleware",
4+
"projectId": "yn8qwi"
5+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
describe('Enhanced middleware', () => {
2+
it('adds request headers', () => {
3+
cy.request('/api/hello').then((response) => {
4+
expect(response.body).to.have.nested.property('headers.x-hello', 'world')
5+
})
6+
})
7+
8+
it('adds request headers to a rewrite', () => {
9+
cy.request('/headers').then((response) => {
10+
expect(response.body).to.have.nested.property('headers.x-hello', 'world')
11+
})
12+
})
13+
14+
it('rewrites the response body', () => {
15+
cy.visit('/static')
16+
cy.get('#message').contains('This was static but has been transformed in')
17+
cy.contains("This is an ad that isn't shown by default")
18+
})
19+
20+
it('modifies the page props', () => {
21+
cy.request('/_next/data/build-id/static.json').then((response) => {
22+
expect(response.body).to.have.nested.property('pageProps.showAd', true)
23+
expect(response.body)
24+
.to.have.nested.property('pageProps.message')
25+
.that.includes('This was static but has been transformed in')
26+
})
27+
})
28+
})
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
describe('Standard middleware', () => {
2+
it('rewrites to internal page', () => {
3+
// preview mode is off by default
4+
cy.visit('/shows/rewriteme')
5+
cy.get('h1').should('contain', 'Show #100')
6+
cy.url().should('eq', `${Cypress.config().baseUrl}/shows/rewriteme`)
7+
})
8+
9+
it('rewrites to external page', () => {
10+
cy.visit('/shows/rewrite-external')
11+
cy.get('h1').should('contain', 'Example Domain')
12+
cy.url().should('eq', `${Cypress.config().baseUrl}/shows/rewrite-external`)
13+
})
14+
15+
it('adds headers to static pages', () => {
16+
cy.request('/shows/static/3').then((response) => {
17+
expect(response.headers).to.have.property('x-middleware-date')
18+
expect(response.headers).to.have.property('x-is-deno', 'true')
19+
expect(response.headers).to.have.property('x-modified-edge', 'true')
20+
})
21+
})
22+
})

0 commit comments

Comments
 (0)