From 3b1d79e56a1be1049f1d46e13cc885634f7bc1ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Huvar?= Date: Mon, 12 Aug 2019 14:02:52 +0200 Subject: [PATCH 01/13] Fix for __dirname --- packages/next/build/webpack-config.ts | 15 +++++++++++++++ packages/next/package.json | 1 + test/integration/api-support/pages/api/dirname.js | 11 +++++++++++ test/integration/api-support/test/index.test.js | 8 ++++++++ yarn.lock | 12 ++++++++++++ 5 files changed, 47 insertions(+) create mode 100644 test/integration/api-support/pages/api/dirname.js diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index d5d3e67e1a40..d16962a4a791 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -63,6 +63,7 @@ export default async function getBaseWebpackConfig( selectivePageBuilding?: boolean } ): Promise { + console.log(dir) const distDir = path.join(dir, config.distDir) const defaultLoaders = { babel: { @@ -504,6 +505,20 @@ export default async function getBaseWebpackConfig( include: [path.join(dir, 'data')], use: 'next-data-loader', }, + isServer && { + test: /\.(tsx|ts|js|mjs|jsx|node)$/, + parser: { amd: false }, + use: { + loader: '@zeit/webpack-asset-relocator-loader', + options: { + filterAssetBase: dir, + emitDirnameAll: false, + emitFilterAssetBaseAll: false, + production: !dev, + debugLog: false, + }, + }, + }, { test: /\.(tsx|ts|js|mjs|jsx)$/, include: [ diff --git a/packages/next/package.json b/packages/next/package.json index 5b1d74709572..a5aee55cfcc6 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -67,6 +67,7 @@ "@babel/preset-typescript": "7.3.3", "@babel/runtime": "7.4.5", "@babel/runtime-corejs2": "7.4.5", + "@zeit/webpack-asset-relocator-loader": "0.6.2", "amphtml-validator": "1.0.23", "async-sema": "3.0.0", "autodll-webpack-plugin": "0.4.2", diff --git a/test/integration/api-support/pages/api/dirname.js b/test/integration/api-support/pages/api/dirname.js new file mode 100644 index 000000000000..eb5d62459f1d --- /dev/null +++ b/test/integration/api-support/pages/api/dirname.js @@ -0,0 +1,11 @@ +import fs from 'fs' +import path from 'path' + +export default (req, res) => { + const fileContent = fs.readFileSync( + path.resolve(__dirname, '..', 'index.js'), + 'utf8' + ) + + res.end(fileContent) +} diff --git a/test/integration/api-support/test/index.test.js b/test/integration/api-support/test/index.test.js index 2ae6cad48f63..806248c555c8 100644 --- a/test/integration/api-support/test/index.test.js +++ b/test/integration/api-support/test/index.test.js @@ -248,6 +248,14 @@ function runTests (serverless = false) { expect(res.status).toBe(404) }) + it('should work with __dirname', async () => { + const data = await fetchViaHTTP(appPort, '/api/dirname', null, {}).then( + res => res.ok && res.text() + ) + + expect(data).toContain('export default () =>
API - support
') + }) + it('should build api routes', async () => { await nextBuild(appDir, [], { stdout: true }) if (serverless) { diff --git a/yarn.lock b/yarn.lock index 2060af993bc3..694ecec9be0d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2601,6 +2601,13 @@ dependencies: "@babel/preset-typescript" "^7.0.0" +"@zeit/webpack-asset-relocator-loader@0.6.2": + version "0.6.2" + resolved "https://registry.yarnpkg.com/@zeit/webpack-asset-relocator-loader/-/webpack-asset-relocator-loader-0.6.2.tgz#b15353d8578562f299eddb94d4b771297acc0487" + integrity sha512-IUz2YvFAv03LHP4dhjHqG549ecZhdp7KU8B+vGfJRgcDzvlCmc9CA1YcYfJHVO96U8dU5z85RIysr2whYUXmgQ== + dependencies: + sourcemap-codec "^1.4.4" + JSONStream@^1.0.4, JSONStream@^1.3.4: version "1.3.5" resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.5.tgz#3208c1f08d3a4d99261ab64f92302bc15e111ca0" @@ -12642,6 +12649,11 @@ source-map@^0.5.0, source-map@^0.5.3, source-map@^0.5.6: resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc" integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w= +sourcemap-codec@^1.4.4: + version "1.4.6" + resolved "https://registry.yarnpkg.com/sourcemap-codec/-/sourcemap-codec-1.4.6.tgz#e30a74f0402bad09807640d39e971090a08ce1e9" + integrity sha512-1ZooVLYFxC448piVLBbtOxFcXwnymH9oUF8nRd3CuYDVvkRBxRl6pB4Mtas5a4drtL+E8LDgFkQNcgIw6tc8Hg== + spawn-sync@^1.0.15: version "1.0.15" resolved "https://registry.yarnpkg.com/spawn-sync/-/spawn-sync-1.0.15.tgz#b00799557eb7fb0c8376c29d44e8a1ea67e57476" From 6f2f8a0249e24dbe776615adea54b480e9292fc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Huvar?= Date: Mon, 12 Aug 2019 14:06:24 +0200 Subject: [PATCH 02/13] Cleanup logs --- packages/next/build/webpack-config.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index d16962a4a791..9c11738b960a 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -63,7 +63,6 @@ export default async function getBaseWebpackConfig( selectivePageBuilding?: boolean } ): Promise { - console.log(dir) const distDir = path.join(dir, config.distDir) const defaultLoaders = { babel: { From 6013200846c6411fa73d29c2799511755c27604f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Huvar?= Date: Mon, 12 Aug 2019 14:14:38 +0200 Subject: [PATCH 03/13] Adjust config --- packages/next/build/webpack-config.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 9c11738b960a..871f7aa7c47f 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -511,8 +511,6 @@ export default async function getBaseWebpackConfig( loader: '@zeit/webpack-asset-relocator-loader', options: { filterAssetBase: dir, - emitDirnameAll: false, - emitFilterAssetBaseAll: false, production: !dev, debugLog: false, }, From adb6362126614d3cfb7fe8c19090428678de291c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Huvar?= Date: Mon, 12 Aug 2019 15:24:53 +0200 Subject: [PATCH 04/13] Add tests for recompile dev --- .../api-support/test/index.test.js | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/test/integration/api-support/test/index.test.js b/test/integration/api-support/test/index.test.js index 806248c555c8..2a20356f4313 100644 --- a/test/integration/api-support/test/index.test.js +++ b/test/integration/api-support/test/index.test.js @@ -10,7 +10,8 @@ import { renderViaHTTP, nextBuild, nextStart, - File + File, + waitFor } from 'next-test-utils' import json from '../big.json' import { createServer } from 'http' @@ -256,6 +257,28 @@ function runTests (serverless = false) { expect(data).toContain('export default () =>
API - support
') }) + it('should work with __dirname and re-compile', async () => { + const dirname = new File(join(appDir, 'pages/api/dirname.js')) + + const data = await fetchViaHTTP(appPort, '/api/dirname', null, {}).then( + res => res.ok && res.text() + ) + + expect(data).toContain('export default () =>
API - support
') + + dirname.replace('index.js', 'user.js') + + await waitFor(500) + + const user = await fetchViaHTTP(appPort, '/api/dirname', null, {}).then( + res => res.ok && res.text() + ) + + expect(user).toContain('export default () =>
User
') + + dirname.restore() + }) + it('should build api routes', async () => { await nextBuild(appDir, [], { stdout: true }) if (serverless) { From b4e2b09c917e39af2383d8a427485cac87d4c603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Huvar?= Date: Mon, 12 Aug 2019 19:31:18 +0200 Subject: [PATCH 05/13] Test for same file recompile not working --- test/integration/api-support/test/index.test.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/test/integration/api-support/test/index.test.js b/test/integration/api-support/test/index.test.js index 2a20356f4313..46467692a2be 100644 --- a/test/integration/api-support/test/index.test.js +++ b/test/integration/api-support/test/index.test.js @@ -258,14 +258,27 @@ function runTests (serverless = false) { }) it('should work with __dirname and re-compile', async () => { - const dirname = new File(join(appDir, 'pages/api/dirname.js')) - const data = await fetchViaHTTP(appPort, '/api/dirname', null, {}).then( res => res.ok && res.text() ) expect(data).toContain('export default () =>
API - support
') + // const index = new File(join(appDir, 'pages/index.js')) + + // index.replace('API', 'IPA') + + // await waitFor(500) + + // const change = await fetchViaHTTP(appPort, '/api/dirname', null, {}).then( + // res => res.ok && res.text() + // ) + // expect(change).toContain('export default () =>
IPA - support
') + + // index.restore() + + const dirname = new File(join(appDir, 'pages/api/dirname.js')) + dirname.replace('index.js', 'user.js') await waitFor(500) From e39b71d88a4f2cf5af9484714e9dd8d122f409d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Huvar?= Date: Tue, 13 Aug 2019 12:57:39 +0200 Subject: [PATCH 06/13] Fix cache for server --- packages/next/build/webpack-config.ts | 1 + test/integration/api-support/test/index.test.js | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 871f7aa7c47f..0e6b93ff6a23 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -317,6 +317,7 @@ export default async function getBaseWebpackConfig( mode: webpackMode, name: isServer ? 'server' : 'client', target: isServer ? 'node' : 'web', + cache: isServer && dev ? false : true, externals: !isServer ? undefined : !isServerless diff --git a/test/integration/api-support/test/index.test.js b/test/integration/api-support/test/index.test.js index 46467692a2be..df4099892e41 100644 --- a/test/integration/api-support/test/index.test.js +++ b/test/integration/api-support/test/index.test.js @@ -264,18 +264,18 @@ function runTests (serverless = false) { expect(data).toContain('export default () =>
API - support
') - // const index = new File(join(appDir, 'pages/index.js')) + const index = new File(join(appDir, 'pages/index.js')) - // index.replace('API', 'IPA') + index.replace('API', 'IPA') - // await waitFor(500) + await waitFor(500) - // const change = await fetchViaHTTP(appPort, '/api/dirname', null, {}).then( - // res => res.ok && res.text() - // ) - // expect(change).toContain('export default () =>
IPA - support
') + const change = await fetchViaHTTP(appPort, '/api/dirname', null, {}).then( + res => res.ok && res.text() + ) + expect(change).toContain('export default () =>
IPA - support
') - // index.restore() + index.restore() const dirname = new File(join(appDir, 'pages/api/dirname.js')) From 4b9212020151bbcf6eff59e4c1e9182df9859120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Huvar?= Date: Thu, 29 Aug 2019 17:48:21 +0200 Subject: [PATCH 07/13] Change tests remove cache --- packages/next/build/webpack-config.ts | 2 -- .../pages/api/{dirname.js => read.js} | 0 test/integration/api-support/pages/api/save.js | 11 +++++++++++ test/integration/api-support/test/index.test.js | 16 +++++++++------- 4 files changed, 20 insertions(+), 9 deletions(-) rename test/integration/api-support/pages/api/{dirname.js => read.js} (100%) create mode 100644 test/integration/api-support/pages/api/save.js diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index c6c1535fdded..1d9f321e48f1 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -314,7 +314,6 @@ export default async function getBaseWebpackConfig( mode: webpackMode, name: isServer ? 'server' : 'client', target: isServer ? 'node' : 'web', - cache: isServer && dev ? false : true, externals: !isServer ? undefined : !isServerless @@ -510,7 +509,6 @@ export default async function getBaseWebpackConfig( options: { filterAssetBase: dir, production: !dev, - debugLog: false, }, }, }, diff --git a/test/integration/api-support/pages/api/dirname.js b/test/integration/api-support/pages/api/read.js similarity index 100% rename from test/integration/api-support/pages/api/dirname.js rename to test/integration/api-support/pages/api/read.js diff --git a/test/integration/api-support/pages/api/save.js b/test/integration/api-support/pages/api/save.js new file mode 100644 index 000000000000..eb5d62459f1d --- /dev/null +++ b/test/integration/api-support/pages/api/save.js @@ -0,0 +1,11 @@ +import fs from 'fs' +import path from 'path' + +export default (req, res) => { + const fileContent = fs.readFileSync( + path.resolve(__dirname, '..', 'index.js'), + 'utf8' + ) + + res.end(fileContent) +} diff --git a/test/integration/api-support/test/index.test.js b/test/integration/api-support/test/index.test.js index df4099892e41..e181f0ef5f43 100644 --- a/test/integration/api-support/test/index.test.js +++ b/test/integration/api-support/test/index.test.js @@ -249,16 +249,16 @@ function runTests (serverless = false) { expect(res.status).toBe(404) }) - it('should work with __dirname', async () => { - const data = await fetchViaHTTP(appPort, '/api/dirname', null, {}).then( + it('should work with __dirname read', async () => { + const data = await fetchViaHTTP(appPort, '/api/read', null, {}).then( res => res.ok && res.text() ) expect(data).toContain('export default () =>
API - support
') }) - it('should work with __dirname and re-compile', async () => { - const data = await fetchViaHTTP(appPort, '/api/dirname', null, {}).then( + it('should work with __dirname read and re-compile', async () => { + const data = await fetchViaHTTP(appPort, '/api/read', null, {}).then( res => res.ok && res.text() ) @@ -270,20 +270,20 @@ function runTests (serverless = false) { await waitFor(500) - const change = await fetchViaHTTP(appPort, '/api/dirname', null, {}).then( + const change = await fetchViaHTTP(appPort, '/api/read', null, {}).then( res => res.ok && res.text() ) expect(change).toContain('export default () =>
IPA - support
') index.restore() - const dirname = new File(join(appDir, 'pages/api/dirname.js')) + const dirname = new File(join(appDir, 'pages/api/read.js')) dirname.replace('index.js', 'user.js') await waitFor(500) - const user = await fetchViaHTTP(appPort, '/api/dirname', null, {}).then( + const user = await fetchViaHTTP(appPort, '/api/read', null, {}).then( res => res.ok && res.text() ) @@ -292,6 +292,8 @@ function runTests (serverless = false) { dirname.restore() }) + // it('should ') + it('should build api routes', async () => { await nextBuild(appDir, [], { stdout: true }) if (serverless) { From f83509dfa9af207c590ce85a82e7f4cec39ec98c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Huvar?= Date: Fri, 30 Aug 2019 11:47:18 +0200 Subject: [PATCH 08/13] Add tests for write --- packages/next/build/webpack-config.ts | 2 ++ test/integration/api-support/pages/api/save.js | 11 +++++------ test/integration/api-support/test/index.test.js | 17 +++++++++++++++-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 1d9f321e48f1..8463b250e2ec 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -509,6 +509,8 @@ export default async function getBaseWebpackConfig( options: { filterAssetBase: dir, production: !dev, + writeMode: true, + relativeToSource: true, }, }, }, diff --git a/test/integration/api-support/pages/api/save.js b/test/integration/api-support/pages/api/save.js index eb5d62459f1d..a88c7ffb5308 100644 --- a/test/integration/api-support/pages/api/save.js +++ b/test/integration/api-support/pages/api/save.js @@ -1,11 +1,10 @@ import fs from 'fs' import path from 'path' -export default (req, res) => { - const fileContent = fs.readFileSync( - path.resolve(__dirname, '..', 'index.js'), - 'utf8' - ) +export default ({ query }, res) => { + const { target } = query - res.end(fileContent) + fs.writeFileSync(path.resolve(__dirname, `${target}.js`), target) + + res.end(target) } diff --git a/test/integration/api-support/test/index.test.js b/test/integration/api-support/test/index.test.js index e181f0ef5f43..67f370cd1e97 100644 --- a/test/integration/api-support/test/index.test.js +++ b/test/integration/api-support/test/index.test.js @@ -1,7 +1,7 @@ /* eslint-env jest */ /* global jasmine */ import { join } from 'path' -import { existsSync, readFileSync } from 'fs' +import { existsSync, readFileSync, unlinkSync } from 'fs' import { killApp, findPort, @@ -292,7 +292,20 @@ function runTests (serverless = false) { dirname.restore() }) - // it('should ') + it('should save file with __dirname', async () => { + const target = `server${serverless ? 'less' : ''}` + const data = await fetchViaHTTP( + appPort, + `/api/save?target=${target}`, + null, + {} + ).then(res => res.ok && res.text()) + const filePath = join(appDir, `pages/api/${target}.js`) + const file = readFileSync(filePath, 'utf8') + expect(data).toBe(target) + expect(file).toBe(target) + unlinkSync(filePath) + }) it('should build api routes', async () => { await nextBuild(appDir, [], { stdout: true }) From da2e896d71ce47169e2bc461e95c2a8401627437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Huvar?= Date: Wed, 11 Sep 2019 10:41:13 +0200 Subject: [PATCH 09/13] Remove save test --- packages/next/build/webpack-config.ts | 2 -- .../api-support/test/index.test.js | 30 +++++++++---------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index d3d00f037322..f2465dc1904c 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -461,8 +461,6 @@ export default async function getBaseWebpackConfig( options: { filterAssetBase: dir, production: !dev, - writeMode: true, - relativeToSource: true, }, }, }, diff --git a/test/integration/api-support/test/index.test.js b/test/integration/api-support/test/index.test.js index 6c32e4e8cb91..4d755f4d3400 100644 --- a/test/integration/api-support/test/index.test.js +++ b/test/integration/api-support/test/index.test.js @@ -1,7 +1,7 @@ /* eslint-env jest */ /* global jasmine */ import { join } from 'path' -import { existsSync, readFileSync, unlinkSync } from 'fs' +import { existsSync, readFileSync } from 'fs' import { killApp, findPort, @@ -322,20 +322,20 @@ function runTests (serverless = false) { dirname.restore() }) - it('should save file with __dirname', async () => { - const target = `server${serverless ? 'less' : ''}` - const data = await fetchViaHTTP( - appPort, - `/api/save?target=${target}`, - null, - {} - ).then(res => res.ok && res.text()) - const filePath = join(appDir, `pages/api/${target}.js`) - const file = readFileSync(filePath, 'utf8') - expect(data).toBe(target) - expect(file).toBe(target) - unlinkSync(filePath) - }) + // it('should save file with __dirname', async () => { + // const target = `server${serverless ? 'less' : ''}` + // const data = await fetchViaHTTP( + // appPort, + // `/api/save?target=${target}`, + // null, + // {} + // ).then(res => res.ok && res.text()) + // const filePath = join(appDir, `pages/api/${target}.js`) + // const file = readFileSync(filePath, 'utf8') + // expect(data).toBe(target) + // expect(file).toBe(target) + // unlinkSync(filePath) + // }) it('should build api routes', async () => { await nextBuild(appDir, [], { stdout: true }) From 53d651fcd7991099b9369bc25892718ff12b8584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Huvar?= Date: Wed, 11 Sep 2019 13:56:54 +0200 Subject: [PATCH 10/13] Adjust tests --- .../pages/api/{read.js => read-server.js} | 0 .../api-support/pages/api/read-serverless.js | 11 +++++++++ .../api-support/test/index.test.js | 24 +++++++++---------- 3 files changed, 22 insertions(+), 13 deletions(-) rename test/integration/api-support/pages/api/{read.js => read-server.js} (100%) create mode 100644 test/integration/api-support/pages/api/read-serverless.js diff --git a/test/integration/api-support/pages/api/read.js b/test/integration/api-support/pages/api/read-server.js similarity index 100% rename from test/integration/api-support/pages/api/read.js rename to test/integration/api-support/pages/api/read-server.js diff --git a/test/integration/api-support/pages/api/read-serverless.js b/test/integration/api-support/pages/api/read-serverless.js new file mode 100644 index 000000000000..eb5d62459f1d --- /dev/null +++ b/test/integration/api-support/pages/api/read-serverless.js @@ -0,0 +1,11 @@ +import fs from 'fs' +import path from 'path' + +export default (req, res) => { + const fileContent = fs.readFileSync( + path.resolve(__dirname, '..', 'index.js'), + 'utf8' + ) + + res.end(fileContent) +} diff --git a/test/integration/api-support/test/index.test.js b/test/integration/api-support/test/index.test.js index 4d755f4d3400..cf4c495b3faa 100644 --- a/test/integration/api-support/test/index.test.js +++ b/test/integration/api-support/test/index.test.js @@ -22,6 +22,8 @@ let server jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2 function runTests (serverless = false) { + const apiRead = `/api/read-server${serverless ? 'less' : ''}` + it('should render page', async () => { const html = await renderViaHTTP(appPort, '/') expect(html).toMatch(/API - support/) @@ -280,7 +282,7 @@ function runTests (serverless = false) { }) it('should work with __dirname read', async () => { - const data = await fetchViaHTTP(appPort, '/api/read', null, {}).then( + const data = await fetchViaHTTP(appPort, apiRead, null, {}).then( res => res.ok && res.text() ) @@ -288,38 +290,34 @@ function runTests (serverless = false) { }) it('should work with __dirname read and re-compile', async () => { - const data = await fetchViaHTTP(appPort, '/api/read', null, {}).then( + const data = await fetchViaHTTP(appPort, apiRead, null, {}).then( res => res.ok && res.text() ) expect(data).toContain('export default () =>
API - support
') - const index = new File(join(appDir, 'pages/index.js')) + const index = new File(join(appDir, `pages${apiRead}.js`)) - index.replace('API', 'IPA') + index.replace('req', '_') await waitFor(500) - const change = await fetchViaHTTP(appPort, '/api/read', null, {}).then( + const change = await fetchViaHTTP(appPort, apiRead, null, {}).then( res => res.ok && res.text() ) - expect(change).toContain('export default () =>
IPA - support
') - - index.restore() + expect(change).toContain('export default () =>
API - support
') - const dirname = new File(join(appDir, 'pages/api/read.js')) - - dirname.replace('index.js', 'user.js') + index.replace('index.js', 'user.js') await waitFor(500) - const user = await fetchViaHTTP(appPort, '/api/read', null, {}).then( + const user = await fetchViaHTTP(appPort, apiRead, null, {}).then( res => res.ok && res.text() ) expect(user).toContain('export default () =>
User
') - dirname.restore() + index.restore() }) // it('should save file with __dirname', async () => { From ecfc5e03b3783e84c6fbf96854c4b875f8312823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Huvar?= Date: Wed, 11 Sep 2019 14:57:57 +0200 Subject: [PATCH 11/13] Adjust tests --- .../pages/api/blog/[post]/comment/[id].js | 3 -- .../api-support/test/index.test.js | 36 +++++++++---------- 2 files changed, 18 insertions(+), 21 deletions(-) delete mode 100644 test/integration/api-support/pages/api/blog/[post]/comment/[id].js diff --git a/test/integration/api-support/pages/api/blog/[post]/comment/[id].js b/test/integration/api-support/pages/api/blog/[post]/comment/[id].js deleted file mode 100644 index 70b2ec0fbc12..000000000000 --- a/test/integration/api-support/pages/api/blog/[post]/comment/[id].js +++ /dev/null @@ -1,3 +0,0 @@ -export default ({ query }, res) => { - res.status(200).json(query) -} diff --git a/test/integration/api-support/test/index.test.js b/test/integration/api-support/test/index.test.js index cf4c495b3faa..35044d9c9610 100644 --- a/test/integration/api-support/test/index.test.js +++ b/test/integration/api-support/test/index.test.js @@ -264,16 +264,16 @@ function runTests (serverless = false) { expect(data).toEqual([{ message: 'Prioritize a non-dynamic api page' }]) }) - it('should return data on dynamic nested route', async () => { - const data = await fetchViaHTTP( - appPort, - '/api/post-1/comment-1', - null, - {} - ).then(res => res.ok && res.json()) + // it('should return data on dynamic nested route', async () => { + // const data = await fetchViaHTTP( + // appPort, + // '/api/post-1/comment-1', + // null, + // {} + // ).then(res => res.ok && res.json()) - expect(data).toEqual({ post: 'post-1', comment: 'comment-1' }) - }) + // expect(data).toEqual({ post: 'post-1', comment: 'comment-1' }) + // }) it('should 404 on optional dynamic api page', async () => { const res = await fetchViaHTTP(appPort, '/api/blog/543/comment', null, {}) @@ -372,16 +372,16 @@ function runTests (serverless = false) { } }) - it('should return data on dynamic optional nested route', async () => { - const data = await fetchViaHTTP( - appPort, - '/api/blog/post-1/comment/1', - null, - {} - ).then(res => res.ok && res.json()) + // it('should return data on dynamic optional nested route', async () => { + // const data = await fetchViaHTTP( + // appPort, + // '/api/blog/post-1/comment/1', + // null, + // {} + // ).then(res => res.ok && res.json()) - expect(data).toEqual({ post: 'post-1', id: '1' }) - }) + // expect(data).toEqual({ post: 'post-1', id: '1' }) + // }) it('should compile only server code in development', async () => { await fetchViaHTTP(appPort, '/') From 52d129f0ce41ff2ccc3c9978435270aef14a6c4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Huvar?= Date: Wed, 11 Sep 2019 18:16:07 +0200 Subject: [PATCH 12/13] Fix tests --- .../pages/api/blog/[post]/comment/[cid].js | 3 ++ .../api-support/test/index.test.js | 36 +++++++++---------- 2 files changed, 21 insertions(+), 18 deletions(-) create mode 100644 test/integration/api-support/pages/api/blog/[post]/comment/[cid].js diff --git a/test/integration/api-support/pages/api/blog/[post]/comment/[cid].js b/test/integration/api-support/pages/api/blog/[post]/comment/[cid].js new file mode 100644 index 000000000000..70b2ec0fbc12 --- /dev/null +++ b/test/integration/api-support/pages/api/blog/[post]/comment/[cid].js @@ -0,0 +1,3 @@ +export default ({ query }, res) => { + res.status(200).json(query) +} diff --git a/test/integration/api-support/test/index.test.js b/test/integration/api-support/test/index.test.js index 35044d9c9610..aa563142f5e2 100644 --- a/test/integration/api-support/test/index.test.js +++ b/test/integration/api-support/test/index.test.js @@ -264,16 +264,16 @@ function runTests (serverless = false) { expect(data).toEqual([{ message: 'Prioritize a non-dynamic api page' }]) }) - // it('should return data on dynamic nested route', async () => { - // const data = await fetchViaHTTP( - // appPort, - // '/api/post-1/comment-1', - // null, - // {} - // ).then(res => res.ok && res.json()) + it('should return data on dynamic nested route', async () => { + const data = await fetchViaHTTP( + appPort, + '/api/post-1/comment-1', + null, + {} + ).then(res => res.ok && res.json()) - // expect(data).toEqual({ post: 'post-1', comment: 'comment-1' }) - // }) + expect(data).toEqual({ post: 'post-1', comment: 'comment-1' }) + }) it('should 404 on optional dynamic api page', async () => { const res = await fetchViaHTTP(appPort, '/api/blog/543/comment', null, {}) @@ -372,16 +372,16 @@ function runTests (serverless = false) { } }) - // it('should return data on dynamic optional nested route', async () => { - // const data = await fetchViaHTTP( - // appPort, - // '/api/blog/post-1/comment/1', - // null, - // {} - // ).then(res => res.ok && res.json()) + it('should return data on dynamic optional nested route', async () => { + const data = await fetchViaHTTP( + appPort, + '/api/blog/post-1/comment/1', + null, + {} + ).then(res => res.ok && res.json()) - // expect(data).toEqual({ post: 'post-1', id: '1' }) - // }) + expect(data).toEqual({ post: 'post-1', cid: '1' }) + }) it('should compile only server code in development', async () => { await fetchViaHTTP(appPort, '/') From cbce18a576848a7d262484a1b0b3a3cbd1bde77d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Huvar?= Date: Wed, 11 Sep 2019 20:57:23 +0200 Subject: [PATCH 13/13] Fix static test --- .../pages/{static.js => static-page.js} | 0 .../empty-object-getInitialProps/test/index.test.js | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename test/integration/empty-object-getInitialProps/pages/{static.js => static-page.js} (100%) diff --git a/test/integration/empty-object-getInitialProps/pages/static.js b/test/integration/empty-object-getInitialProps/pages/static-page.js similarity index 100% rename from test/integration/empty-object-getInitialProps/pages/static.js rename to test/integration/empty-object-getInitialProps/pages/static-page.js diff --git a/test/integration/empty-object-getInitialProps/test/index.test.js b/test/integration/empty-object-getInitialProps/test/index.test.js index 193696fb89bc..1d83d70710f1 100644 --- a/test/integration/empty-object-getInitialProps/test/index.test.js +++ b/test/integration/empty-object-getInitialProps/test/index.test.js @@ -40,7 +40,7 @@ describe('Empty Project', () => { it('It should not show empty object warning for page without `getInitialProps`', async () => { output = '' - await renderViaHTTP(appPort, '/static') + await renderViaHTTP(appPort, '/static-page') await waitFor(100) expect(output).not.toMatch( /returned an empty object from `getInitialProps`/ @@ -48,7 +48,7 @@ describe('Empty Project', () => { }) it('should show empty object warning during client transition', async () => { - const browser = await webdriver(appPort, '/static') + const browser = await webdriver(appPort, '/static-page') await browser.eval(`(function() { window.gotWarn = false const origWarn = console.warn