Skip to content

Commit

Permalink
Add full end-to-end integration tests
Browse files Browse the repository at this point in the history
Full end-to-end integration tests for Twitter (OAuth 1) and GitHub (OAuth 2) using Puppeteer and Mocha.

This replaces Cypress tests due to issues with Cypress not being able to run tests against external URLs, which we need for our integration tests.

The integration test runner is hosted outside of GitHub Actions (it cannot be hosted by GitHub or on AWS due to IP access controls placed on sign in by providers like Twitter and GitHub) and so the integration tests may not pass if the test runner is offline. If this happens, tests can be re-run later when the test runner is available.

See Pull Request nextauthjs#641 for details.
  • Loading branch information
iaincollins authored Sep 8, 2020
1 parent 6d63b74 commit 3b40335
Show file tree
Hide file tree
Showing 26 changed files with 1,363 additions and 1,915 deletions.
13 changes: 13 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_TWITTER_ID=
NEXTAUTH_TWITTER_SECRET=
NEXTAUTH_TWITTER_USERNAME=
NEXTAUTH_TWITTER_PASSWORD=
NEXTAUTH_GITHUB_ID=
NEXTAUTH_GITHUB_SECRET=
NEXTAUTH_GITHUB_USERNAME=
NEXTAUTH_GITHUB_PASSWORD=
NEXTAUTH_GOOGLE_ID=
NEXTAUTH_GOOGLE_SECRET=
NEXTAUTH_GOOGLE_USERNAME=
NEXTAUTH_GOOGLE_PASSWORD=
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Simple check that the build is valid and no linting errors.
# Currently is run as a seperate workflow as it's fast to fail.
name: Test build and linting
name: Build Test

on:
push:
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Integration Test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
# runs-on: ubuntu-latest
runs-on: self-hosted

# Target time is under 5 minutes to run all tests. If it takes longer than
# 10 minutes should look at running tests in parallel. No individual flow
# should take longer than 5 minutes to build and run.
timeout-minutes: 10

strategy:
matrix:
node-version: [12.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

# Install dependencies
- run: npm ci

# Run tests (build library, build + start test app in Docker, run tests)
- run: npm test
# TODO Tests should exit out if env vars not set (currently hangs)
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
NEXTAUTH_TWITTER_ID: ${{secrets.NEXTAUTH_TWITTER_ID}}
NEXTAUTH_TWITTER_SECRET: ${{secrets.NEXTAUTH_TWITTER_SECRET}}
NEXTAUTH_TWITTER_USERNAME: ${{secrets.NEXTAUTH_TWITTER_USERNAME}}
NEXTAUTH_TWITTER_PASSWORD: ${{secrets.NEXTAUTH_TWITTER_PASSWORD}}
NEXTAUTH_GITHUB_ID: ${{secrets.NEXTAUTH_GITHUB_ID}}
NEXTAUTH_GITHUB_SECRET: ${{secrets.NEXTAUTH_GITHUB_SECRET}}
NEXTAUTH_GITHUB_USERNAME: ${{secrets.NEXTAUTH_GITHUB_USERNAME}}
NEXTAUTH_GITHUB_PASSWORD: ${{secrets.NEXTAUTH_GITHUB_PASSWORD}}
37 changes: 0 additions & 37 deletions .github/workflows/test-integration.yml

This file was deleted.

39 changes: 21 additions & 18 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
.next
.env
.vscode
node_modules
dist
.DS_Store# Dependencies
/node_modules

# Production
/build

# Generated files
.docusaurus
.cache-loader

# Misc
.DS_Store

.env
.env.local
.env.development.local
.env.test.local
Expand All @@ -24,10 +11,26 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Docusaurus
www/build
# Dependencies
node_modules

# Build dirs
.next
/build
/dist
/www/build

# Generated files
.docusaurus
.cache-loader
.next

#VS
# VS
/.vs/slnx.sqlite-journal
/.vs/slnx.sqlite
/.vs
.vscode

# GitHub Actions runner
/actions-runner
/_work
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ WORKDIR /usr/src/app

# Install basic dependancies (Next.js, React)
COPY test/docker/app/package*.json ./
RUN npm ci
RUN npm ci --only=production

FROM node:10-alpine as app
COPY --from=base /usr/src/app ./
Expand All @@ -20,7 +20,7 @@ COPY index.js providers.js adapters.js client.js jwt.js node_modules/next-auth/
COPY dist node_modules/next-auth/dist
# Copy the package.json for the library and install it's dependences
COPY package*.json node_modules/next-auth/
RUN cd node_modules/next-auth/ && npm ci
RUN cd node_modules/next-auth/ && npm ci --only=production

# Copy test pages across
COPY test/docker/app/pages ./pages
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# NextAuth.js

![Build Test](https://github.com/nextauthjs/next-auth/workflows/Build%20Test/badge.svg)
![Integration Test](https://github.com/nextauthjs/next-auth/workflows/Integration%20Test/badge.svg)

## Overview

NextAuth.js is a complete open source authentication solution for [Next.js](http://nextjs.org/) applications.
Expand Down
4 changes: 0 additions & 4 deletions cypress.json

This file was deleted.

5 changes: 0 additions & 5 deletions cypress/fixtures/example.json

This file was deleted.

23 changes: 0 additions & 23 deletions cypress/integration/pages/signin.spec.js

This file was deleted.

14 changes: 0 additions & 14 deletions cypress/integration/pages/signout.spec.js

This file was deleted.

23 changes: 0 additions & 23 deletions cypress/integration/pages/verify-request.spec.js

This file was deleted.

34 changes: 0 additions & 34 deletions cypress/integration/workflows/email.spec.js

This file was deleted.

46 changes: 0 additions & 46 deletions cypress/integration/workflows/providers.spec.js

This file was deleted.

21 changes: 0 additions & 21 deletions cypress/plugins/index.js

This file was deleted.

26 changes: 0 additions & 26 deletions cypress/support/commands.js

This file was deleted.

Loading

0 comments on commit 3b40335

Please sign in to comment.