Skip to content

Commit

Permalink
Added Next.js + Cypress test (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
neogeek authored Jun 7, 2022
1 parent 43353b4 commit 7fdfd82
Show file tree
Hide file tree
Showing 10 changed files with 1,970 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"test": "pnpm -r --workspace-concurrency 1 --filter=./playgrounds/* test",
"test:cjs": "pnpm -r --workspace-concurrency 1 --filter=./playgrounds/cjs test",
"test:esm": "pnpm -r --workspace-concurrency 1 --filter=./playgrounds/esm test",
"test:nextjs": "pnpm -r --workspace-concurrency 1 --filter=./playgrounds/nextjs test",
"compile": "pnpm -r --workspace-concurrency 1 --filter=./playgrounds/* compile"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions playgrounds/nextjs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.next
9 changes: 9 additions & 0 deletions playgrounds/nextjs/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'cypress';

export default defineConfig({
e2e: {
baseUrl: 'https://www.google.com',
supportFile: false,
video: false,
},
});
15 changes: 15 additions & 0 deletions playgrounds/nextjs/cypress/e2e/sample.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { faker } from '@faker-js/faker';

describe('Search', () => {
it('should search for random word', () => {
const word = faker.word.noun();

cy.visit('https://google.com');

cy.get('input[name="q"]').type(word);

cy.get('form[role="search"]').submit();

cy.url().should('include', `https://www.google.com/search?q=${word}`);
});
});
5 changes: 5 additions & 0 deletions playgrounds/nextjs/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
28 changes: 28 additions & 0 deletions playgrounds/nextjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "faker-nextjs-test",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"compile": "next build",
"test": "cypress run"
},
"dependencies": {
"next": "12.1.6",
"react": "18.1.0",
"react-dom": "18.1.0"
},
"devDependencies": {
"@faker-js/faker": "7.2.0",
"@types/node": "17.0.40",
"@types/react": "18.0.12",
"@types/react-dom": "18.0.5",
"cypress": "10.0.3",
"eslint": "8.17.0",
"eslint-config-next": "12.1.6",
"typescript": "4.7.3"
}
}
7 changes: 7 additions & 0 deletions playgrounds/nextjs/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { AppProps } from 'next/app';

function MyApp({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />;
}

export default MyApp;
25 changes: 25 additions & 0 deletions playgrounds/nextjs/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { NextPage } from 'next';

import { faker } from '@faker-js/faker';

export async function getServerSideProps() {
return {
props: {
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
},
};
}

const Home: NextPage<{ firstName: string; lastName: string }> = ({
firstName,
lastName,
}) => {
return (
<h1>
Welcome {firstName} {lastName}!
</h1>
);
};

export default Home;
21 changes: 21 additions & 0 deletions playgrounds/nextjs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"types": ["cypress"]
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
Loading

0 comments on commit 7fdfd82

Please sign in to comment.