From 376f325b1dab3a19a6f36419a90b0632dfa19737 Mon Sep 17 00:00:00 2001 From: Alex Newman Date: Mon, 3 Apr 2017 23:51:26 +0100 Subject: [PATCH] Add integration tests, and update `.gitignore` --- .gitignore | 2 + readme.md | 1 - test/integration/distDir/next.config.js | 7 +++ test/integration/distDir/pages/index.js | 3 ++ test/integration/distDir/test/index.test.js | 49 +++++++++++++++++++++ 5 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 test/integration/distDir/next.config.js create mode 100644 test/integration/distDir/pages/index.js create mode 100644 test/integration/distDir/test/index.test.js diff --git a/.gitignore b/.gitignore index 1a60afccbeee..1f02e940c27a 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ npm-debug.log # coverage .nyc_output coverage + +.DS_Store diff --git a/readme.md b/readme.md index e2d979fd21e2..3f5c607b1b4c 100644 --- a/readme.md +++ b/readme.md @@ -641,7 +641,6 @@ module.exports = { } ``` - ### Customizing webpack config In order to extend our usage of `webpack`, you can define a function that extends its config via `next.config.js`. diff --git a/test/integration/distDir/next.config.js b/test/integration/distDir/next.config.js new file mode 100644 index 000000000000..db58ee17b506 --- /dev/null +++ b/test/integration/distDir/next.config.js @@ -0,0 +1,7 @@ +module.exports = { + onDemandEntries: { + // Make sure entries are not getting disposed. + maxInactiveAge: 1000 * 60 * 60 + }, + distDir: 'dist' +} diff --git a/test/integration/distDir/pages/index.js b/test/integration/distDir/pages/index.js new file mode 100644 index 000000000000..3d446a4e89b8 --- /dev/null +++ b/test/integration/distDir/pages/index.js @@ -0,0 +1,3 @@ +export default () => ( +
Hello World
+) diff --git a/test/integration/distDir/test/index.test.js b/test/integration/distDir/test/index.test.js new file mode 100644 index 000000000000..913f223f230f --- /dev/null +++ b/test/integration/distDir/test/index.test.js @@ -0,0 +1,49 @@ +/* global jasmine, describe, it, expect, beforeAll, afterAll */ + +import { join } from 'path' +import { existsSync } from 'fs' +import { + nextServer, + nextBuild, + startApp, + stopApp, + renderViaHTTP +} from 'next-test-utils' + +const appDir = join(__dirname, '../') +let appPort +let server +let app +jasmine.DEFAULT_TIMEOUT_INTERVAL = 40000 + +describe('Production Usage', () => { + beforeAll(async () => { + await nextBuild(appDir) + app = nextServer({ + dir: join(__dirname, '../'), + dev: false, + quiet: true + }) + + server = await startApp(app) + appPort = server.address().port + }) + afterAll(() => stopApp(server)) + + describe('With basic usage', () => { + it('should render the page', async () => { + const html = await renderViaHTTP(appPort, '/') + expect(html).toMatch(/Hello World/) + }) + }) + + describe('File locations', () => { + it('should build the app within the given `dist` directory', () => { + expect(existsSync(join(__dirname, '/../dist/app.js'))).toBeTruthy() + }) + + it('should not build the app within the default `.next` directory', () => { + expect(existsSync(join(__dirname, '/../.next/app.js'))).toBeFalsy() + }) + }) +})