Skip to content

Commit 717a548

Browse files
author
Tiffany Le-Nguyen
authored
chore: add e2e tests and demos (#1172)
* chore: recommit as one * chore: fix eslint * chore: fix eslint * chore: fix order and typo * chore: add middleware test * chore: redo lock * chore: update snapidoos * chore: snapidoos please * chore: update to node version 16 * chore: update to npm 8 * chore: swc please * chore: snapidoodidoo * chore: snapidoodidoodoo * chore: manual snap * chore: manual snap 2 * Apply suggestions from code review
1 parent ef13731 commit 717a548

24 files changed

+23567
-3980
lines changed

.vscode/feat-test.code-snippets

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
// Place your netlify-plugin-nextjs workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
3+
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
4+
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
5+
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
6+
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
7+
// Placeholders with the same ids are connected.
8+
// Example:
9+
"Create Next Test Feature": {
10+
"scope": "javascriptreact,typescriptreact",
11+
"prefix": "ft",
12+
"body": [
13+
"import Link from 'next/link'",
14+
"",
15+
"function $1() {",
16+
"\treturn (",
17+
"\t\t<div>",
18+
"\t\t<h1>$1</h1>",
19+
"\t\t<Link href=\"\"><a>Read Docs</a></Link>",
20+
"\t\t<p>Description of feature</p>",
21+
"\t\t<p>Example/test of feature</p>",
22+
"\t\t</div>",
23+
"\t)",
24+
"}",
25+
"",
26+
"export default $1"
27+
],
28+
"description": "Log output to console"
29+
}
30+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
describe('CSS handling', () => {
2+
beforeEach(() => {
3+
cy.visit('/css')
4+
})
5+
6+
it('should properly handle css', () => {
7+
// Sass variable loaded
8+
cy.findByText(/ Sass variable imported, color: #64FF00/i)
9+
10+
// CSS-in-JS loaded
11+
cy.findByTestId('css-in-js').should('have.css', 'background', 'rgb(255, 165, 0) none repeat scroll 0% 0% / auto padding-box border-box')
12+
})
13+
})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
describe('Environment Varialbes', () => {
2+
beforeEach(() => {
3+
cy.visit('/env')
4+
})
5+
6+
it('should show a public environment token and not show private ones', () => {
7+
cy.findByText('Greetings Vi')
8+
cy.findByText('Everything worked')
9+
})
10+
})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
describe('Layouts', () => {
2+
beforeEach(() => {
3+
cy.visit('/layouts')
4+
})
5+
6+
it('should properly have a layout and title change', () => {
7+
cy.findByText(/Test layout wrapper/i)
8+
cy.title().should('eq', 'Per Page Layout test title')
9+
})
10+
})
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
describe('Middleware', () => {
2+
beforeEach(() => {
3+
cy.request('/middle')
4+
})
5+
6+
it('should properly load custom headers', () => {
7+
cy.request({
8+
url: '/',
9+
}).then((response) => {
10+
expect(response.headers).to.have.property('x-custom-1', 'value-1')
11+
expect(response.headers).to.have.property('x-custom-2', 'value-2')
12+
expect(response.headers).to.have.property('x-custom-3', 'value-3')
13+
expect(response.headers).to.have.property('x-custom-4', 'value-4')
14+
})
15+
})
16+
})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
describe('Environment Varialbes', () => {
2+
beforeEach(() => {
3+
cy.intercept('GET', 'https://www.googletagmanager.com/gtm.js?id=GTM-XXXXXX').as('test-gtm')
4+
cy.visit('https://61f2c7c9fad2c70ee2737a81--netlify-plugin-nextjs-demo.netlify.app/script/')
5+
})
6+
7+
it('should load a script after interactive', () => {
8+
cy.wait('@test-gtm')
9+
})
10+
})

demos/default/.env.production

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
HELLO_WORLD="Hello Production"
1+
HELLO_WORLD="Hello Production"
2+
3+
TEST_ENV_VAR="This test shouldn't show up on the page. If it does, something is wrong"
4+
5+
# In order to expose a variable to the browser you have to prefix the variable with NEXT_PUBLIC_.
6+
7+
NEXT_PUBLIC_NAME="Vi"
8+
NEXT_PUBLIC_GREETINGS="Greetings $NEXT_PUBLIC_NAME"

demos/default/next-env.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference types="next" />
2+
/// <reference types="next/image-types/global" />
3+
4+
// NOTE: This file should not be edited
5+
// see https://nextjs.org/docs/basic-features/typescript for more information.

demos/default/next.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const path = require('path')
2+
13
module.exports = {
24
// Configurable site features we support:
35
// distDir: 'build',
@@ -49,4 +51,12 @@ module.exports = {
4951
},
5052
]
5153
},
54+
// https://nextjs.org/docs/basic-features/image-optimization#domains
55+
images: {
56+
domains: ['raw.githubusercontent.com'],
57+
},
58+
// https://nextjs.org/docs/basic-features/built-in-css-support#customizing-sass-options
59+
sassOptions: {
60+
includePaths: [path.join(__dirname, 'styles-sass-test')],
61+
},
5262
}

demos/default/pages/_app.js renamed to demos/default/pages/_app.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import '../styles/globals.css'
22

33
function MyApp({ Component, pageProps }) {
4+
const getLayout = Component.getLayout || ((page) => page)
5+
46
return (
57
<div className='prose ml-14 mt-10 mb-20'>
6-
<Component {...pageProps} />
8+
{getLayout(<Component {...pageProps} />)}
79
</div>
810
)
911
}

0 commit comments

Comments
 (0)