From a3e5c82957054999b2cc59aa02333b0c089e051c Mon Sep 17 00:00:00 2001 From: James Mosier Date: Wed, 22 Jan 2020 14:13:23 -0500 Subject: [PATCH 1/2] Added support for bigint to API routes Closes #7980 --- packages/next/build/babel/preset.ts | 1 + packages/next/package.json | 1 + test/integration/bigint/pages/api/bigint.js | 4 ++ test/integration/bigint/test/index.test.js | 71 +++++++++++++++++++++ yarn.lock | 12 ++++ 5 files changed, 89 insertions(+) create mode 100644 test/integration/bigint/pages/api/bigint.js create mode 100644 test/integration/bigint/test/index.test.js diff --git a/packages/next/build/babel/preset.ts b/packages/next/build/babel/preset.ts index ac886d86fa8a7..dcf28d7824e4e 100644 --- a/packages/next/build/babel/preset.ts +++ b/packages/next/build/babel/preset.ts @@ -178,6 +178,7 @@ module.exports = ( ], require('@babel/plugin-proposal-optional-chaining'), require('@babel/plugin-proposal-nullish-coalescing-operator'), + isServer && require('@babel/plugin-syntax-bigint'), ].filter(Boolean), } } diff --git a/packages/next/package.json b/packages/next/package.json index 6203148e6577b..ef1027dc618ff 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -63,6 +63,7 @@ "@babel/plugin-proposal-nullish-coalescing-operator": "7.7.4", "@babel/plugin-proposal-object-rest-spread": "7.6.2", "@babel/plugin-proposal-optional-chaining": "7.7.4", + "@babel/plugin-syntax-bigint": "7.8.3", "@babel/plugin-syntax-dynamic-import": "7.2.0", "@babel/plugin-transform-modules-commonjs": "7.7.0", "@babel/plugin-transform-runtime": "7.6.2", diff --git a/test/integration/bigint/pages/api/bigint.js b/test/integration/bigint/pages/api/bigint.js new file mode 100644 index 0000000000000..8baefcfb20304 --- /dev/null +++ b/test/integration/bigint/pages/api/bigint.js @@ -0,0 +1,4 @@ +export default (req, res) => { + res.statusCode = 200 + res.send((1n + 2n).toString()) +} diff --git a/test/integration/bigint/test/index.test.js b/test/integration/bigint/test/index.test.js new file mode 100644 index 0000000000000..a867a4e0faaf4 --- /dev/null +++ b/test/integration/bigint/test/index.test.js @@ -0,0 +1,71 @@ +/* eslint-env jest */ +/* global jasmine */ +import fs from 'fs-extra' +import { join } from 'path' +import { + fetchViaHTTP, + launchApp, + nextBuild, + nextStart, + killApp, + findPort, +} from 'next-test-utils' + +jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2 + +const appDir = join(__dirname, '..') +const nextConfig = join(appDir, 'next.config.js') +let appPort +let app + +const runTests = () => { + it('should return 200', async () => { + const res = await fetchViaHTTP(appPort, '/api/bigint', null, { + method: 'GET', + }) + + expect(res.status).toEqual(200) + }) +} + +describe('bigint API route support', () => { + describe('dev mode', () => { + beforeAll(async () => { + appPort = await findPort() + app = await launchApp(appDir, appPort) + }) + afterAll(() => killApp(app)) + + runTests() + }) + + describe('server mode', () => { + beforeAll(async () => { + await fs.remove(nextConfig) + await nextBuild(appDir) + appPort = await findPort() + app = await nextStart(appDir, appPort) + }) + afterAll(() => killApp(app)) + + runTests() + }) + + describe('serverless mode', () => { + beforeAll(async () => { + await fs.writeFile( + nextConfig, + `module.exports = { target: 'serverless' }` + ) + await nextBuild(appDir) + appPort = await findPort() + app = await nextStart(appDir, appPort) + }) + afterAll(async () => { + await killApp(app) + await fs.remove(nextConfig) + }) + + runTests() + }) +}) diff --git a/yarn.lock b/yarn.lock index 46d1480b54c51..38f1f3a9f96ba 100644 --- a/yarn.lock +++ b/yarn.lock @@ -220,6 +220,11 @@ resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.0.0.tgz#bbb3fbee98661c569034237cc03967ba99b4f250" integrity sha512-CYAOUCARwExnEixLdB6sDm2dIJ/YgEAKDM1MOeMeZu9Ld/bDgVo8aiWrXwcY7OBh+1Ea2uUcVRcxKk0GJvW7QA== +"@babel/helper-plugin-utils@^7.8.0": + version "7.8.3" + resolved "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.8.3.tgz#9ea293be19babc0f52ff8ca88b34c3611b208670" + integrity sha512-j+fq49Xds2smCUNYmEHF9kGNkhbet6yVIBp4e6oeQpH1RUs/Ir06xUKzDjDkGcaaokPiTNs2JBWHjaE4csUkZQ== + "@babel/helper-regex@^7.0.0", "@babel/helper-regex@^7.4.4": version "7.5.5" resolved "https://registry.yarnpkg.com/@babel/helper-regex/-/helper-regex-7.5.5.tgz#0aa6824f7100a2e0e89c1527c23936c152cab351" @@ -384,6 +389,13 @@ dependencies: "@babel/helper-plugin-utils" "^7.0.0" +"@babel/plugin-syntax-bigint@7.8.3": + version "7.8.3" + resolved "https://registry.npmjs.org/@babel/plugin-syntax-bigint/-/plugin-syntax-bigint-7.8.3.tgz#4c9a6f669f5d0cdf1b90a1671e9a146be5300cea" + integrity sha512-wnTnFlG+YxQm3vDxpGE57Pj0srRU4sHE/mDkt1qv2YJJSeUAec2ma4WLUnUPeKjyrfntVwe/N6dCXpU+zL3Npg== + dependencies: + "@babel/helper-plugin-utils" "^7.8.0" + "@babel/plugin-syntax-dynamic-import@7.2.0": version "7.2.0" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-dynamic-import/-/plugin-syntax-dynamic-import-7.2.0.tgz#69c159ffaf4998122161ad8ebc5e6d1f55df8612" From 7ad33e4a779f6ec8c9591282f44bf8ff52da96ae Mon Sep 17 00:00:00 2001 From: James Mosier Date: Wed, 22 Jan 2020 15:10:05 -0500 Subject: [PATCH 2/2] added BigInt test to get result --- test/integration/bigint/test/index.test.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/integration/bigint/test/index.test.js b/test/integration/bigint/test/index.test.js index a867a4e0faaf4..b4d49886ab08b 100644 --- a/test/integration/bigint/test/index.test.js +++ b/test/integration/bigint/test/index.test.js @@ -23,9 +23,15 @@ const runTests = () => { const res = await fetchViaHTTP(appPort, '/api/bigint', null, { method: 'GET', }) - expect(res.status).toEqual(200) }) + + it('should return the BigInt result text', async () => { + const resText = await fetchViaHTTP(appPort, '/api/bigint', null, { + method: 'GET', + }).then(res => res.ok && res.text()) + expect(resText).toEqual('3') + }) } describe('bigint API route support', () => {