Files
archived-next-auth/test/integration/github.js
Iain Collins 0adfba8c5c Improve Puppeteer configuration (#658)
* Centralises configuration for Puppeteer used in tests to make it easier to maintain.
* Adds support for running tests on ARM, so we can use Raspberry Pi test runners off the cloud to get around block lists.
* Includes improved stealth mode to avoid detection which breaks integration tests.
2020-09-11 01:41:02 +01:00

71 lines
2.1 KiB
JavaScript

require('dotenv').config()
const assert = require('assert')
const { puppeteer, puppeteerOptions } = require('../lib/puppeteer')
const BASE_URL = 'http://localhost:3000'
const CALLBACK_URL = `${BASE_URL}/test`
const {
NEXTAUTH_GITHUB_USERNAME: USERNAME,
NEXTAUTH_GITHUB_PASSWORD: PASSWORD
} = process.env
describe('GitHub (OAuth 2.0 flow)', function () {
this.slow(5000)
this.timeout(1000 * 60)
let browser,page
before(async () => {
browser = await puppeteer.launch(puppeteerOptions)
page = await browser.newPage()
return Promise.resolve()
})
it('should show button on sign in page', async function () {
page.setDefaultTimeout(1000 * 60)
await page.goto(`${BASE_URL}/api/auth/signin?callbackUrl=${encodeURIComponent(CALLBACK_URL)}`)
await page.waitForSelector(`form[action="${BASE_URL}/api/auth/signin/github"] button`)
await page.click(`form[action="${BASE_URL}/api/auth/signin/github"] button`)
return Promise.resolve()
})
it('should be redirected to provider', async function () {
// Enter username
await page.waitForSelector('input[name="login"]')
await page.click('input[name="login"]')
await page.keyboard.type(USERNAME)
// Enter password
await page.waitForSelector('input[name="password"]')
await page.click('input[name="password"]')
await page.keyboard.type(PASSWORD)
return Promise.resolve()
})
it('should be able to sign in with provider', async function () {
// Click submit
await page.click('form[action="/session"] [type="submit"]')
return Promise.resolve()
})
it('should be returned to callback URL', async function () {
// Wait for page to return to callback URL
await page.waitForSelector('#nextauth-test-page')
// Check we are at the correct callback URL
assert.equal(page.url(), CALLBACK_URL)
return Promise.resolve()
})
it('should be signed in', async function () {
// Check we are signed in
await page.waitForSelector('#nextauth-signed-in')
return Promise.resolve()
})
after(async () => {
await browser.close()
return Promise.resolve()
})
})