Skip to content

Commit

Permalink
Merge branch 'canary' into feat/transform-runtime-version
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer authored Jan 20, 2020
2 parents fad8b42 + eb38d22 commit eb3e6fb
Show file tree
Hide file tree
Showing 9 changed files with 248 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function getOptimizedAliases(isServer: boolean): { [pkg: string]: string } {
'object.assign/shim': path.join(shimAssign, 'shim.js'),

// Replace: full URL polyfill with platform-based polyfill
url: require.resolve('native-url'),
// url: require.resolve('native-url'),
}
}

Expand Down
1 change: 0 additions & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@
"lru-cache": "5.1.1",
"mini-css-extract-plugin": "0.8.0",
"mkdirp": "0.5.1",
"native-url": "0.2.4",
"node-fetch": "2.6.0",
"object-assign": "4.1.1",
"ora": "3.4.0",
Expand Down
7 changes: 7 additions & 0 deletions test/integration/query-with-encoding/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const Index = ({ query }) => (
<pre id="query-content">{JSON.stringify(query)}</pre>
)

Index.getInitialProps = ({ query }) => ({ query })

export default Index
15 changes: 15 additions & 0 deletions test/integration/query-with-encoding/pages/newline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Link from 'next/link'

const Another = () => (
<div>
<Link href="/?another=hello%0A">
<a id="hello-lf">Hello LF</a>
</Link>
<br />
<Link href={{ pathname: '/', query: { complex: 'yes\n' } }}>
<a id="hello-complex">Hello Complex</a>
</Link>
</div>
)

export default Another
15 changes: 15 additions & 0 deletions test/integration/query-with-encoding/pages/percent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Link from 'next/link'

const Another = () => (
<div>
<Link href="/?another=hello%25">
<a id="hello-percent">Hello %</a>
</Link>
<br />
<Link href={{ pathname: '/', query: { complex: 'yes%' } }}>
<a id="hello-complex">Hello Complex</a>
</Link>
</div>
)

export default Another
15 changes: 15 additions & 0 deletions test/integration/query-with-encoding/pages/space.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Link from 'next/link'

const Another = () => (
<div>
<Link href="/?another=hello%20">
<a id="hello-space">Hello Space</a>
</Link>
<br />
<Link href={{ pathname: '/', query: { complex: 'yes ' } }}>
<a id="hello-complex">Hello Complex</a>
</Link>
</div>
)

export default Another
193 changes: 193 additions & 0 deletions test/integration/query-with-encoding/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
/* eslint-env jest */
/* global jasmine */
import {
nextBuild,
nextServer,
startApp,
stopApp,
waitFor,
} from 'next-test-utils'
import webdriver from 'next-webdriver'
import { join } from 'path'

jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2

const appDir = join(__dirname, '..')

let appPort
let app
let server

describe('Query String with Encoding', () => {
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('new line', () => {
it('should have correct query on SSR', async () => {
const browser = await webdriver(appPort, '/?test=abc%0A')
try {
const text = await browser.elementByCss('#query-content').text()
expect(text).toBe('{"test":"abc\\n"}')
} finally {
await browser.close()
}
})

it('should have correct query on Router#push', async () => {
const browser = await webdriver(appPort, '/')
try {
await waitFor(2000)
await browser.eval(
`window.next.router.push({pathname:'/',query:{abc:'def\\n'}})`
)
await waitFor(1000)
const text = await browser.elementByCss('#query-content').text()
expect(text).toBe('{"abc":"def\\n"}')
} finally {
await browser.close()
}
})

it('should have correct query on simple client-side <Link>', async () => {
const browser = await webdriver(appPort, '/newline')
try {
await waitFor(2000)
await browser.elementByCss('#hello-lf').click()
await waitFor(1000)
const text = await browser.elementByCss('#query-content').text()
expect(text).toBe('{"another":"hello\\n"}')
} finally {
await browser.close()
}
})

it('should have correct query on complex client-side <Link>', async () => {
const browser = await webdriver(appPort, '/newline')
try {
await waitFor(2000)
await browser.elementByCss('#hello-complex').click()
await waitFor(1000)
const text = await browser.elementByCss('#query-content').text()
expect(text).toBe('{"complex":"yes\\n"}')
} finally {
await browser.close()
}
})
})

describe('trailing space', () => {
it('should have correct query on SSR', async () => {
const browser = await webdriver(appPort, '/?test=abc%20')
try {
const text = await browser.elementByCss('#query-content').text()
expect(text).toBe('{"test":"abc "}')
} finally {
await browser.close()
}
})

it('should have correct query on Router#push', async () => {
const browser = await webdriver(appPort, '/')
try {
await waitFor(2000)
await browser.eval(
`window.next.router.push({pathname:'/',query:{abc:'def '}})`
)
await waitFor(1000)
const text = await browser.elementByCss('#query-content').text()
expect(text).toBe('{"abc":"def "}')
} finally {
await browser.close()
}
})

it('should have correct query on simple client-side <Link>', async () => {
const browser = await webdriver(appPort, '/space')
try {
await waitFor(2000)
await browser.elementByCss('#hello-space').click()
await waitFor(1000)
const text = await browser.elementByCss('#query-content').text()
expect(text).toBe('{"another":"hello "}')
} finally {
await browser.close()
}
})

it('should have correct query on complex client-side <Link>', async () => {
const browser = await webdriver(appPort, '/space')
try {
await waitFor(2000)
await browser.elementByCss('#hello-complex').click()
await waitFor(1000)
const text = await browser.elementByCss('#query-content').text()
expect(text).toBe('{"complex":"yes "}')
} finally {
await browser.close()
}
})
})

describe('percent', () => {
it('should have correct query on SSR', async () => {
const browser = await webdriver(appPort, '/?test=abc%25')
try {
const text = await browser.elementByCss('#query-content').text()
expect(text).toBe('{"test":"abc%"}')
} finally {
await browser.close()
}
})

it('should have correct query on Router#push', async () => {
const browser = await webdriver(appPort, '/')
try {
await waitFor(2000)
await browser.eval(
`window.next.router.push({pathname:'/',query:{abc:'def%'}})`
)
await waitFor(1000)
const text = await browser.elementByCss('#query-content').text()
expect(text).toBe('{"abc":"def%"}')
} finally {
await browser.close()
}
})

it('should have correct query on simple client-side <Link>', async () => {
const browser = await webdriver(appPort, '/percent')
try {
await waitFor(2000)
await browser.elementByCss('#hello-percent').click()
await waitFor(1000)
const text = await browser.elementByCss('#query-content').text()
expect(text).toBe('{"another":"hello%"}')
} finally {
await browser.close()
}
})

it('should have correct query on complex client-side <Link>', async () => {
const browser = await webdriver(appPort, '/percent')
try {
await waitFor(2000)
await browser.elementByCss('#hello-complex').click()
await waitFor(1000)
const text = await browser.elementByCss('#query-content').text()
expect(text).toBe('{"complex":"yes%"}')
} finally {
await browser.close()
}
})
})
})
4 changes: 2 additions & 2 deletions test/integration/size-limit/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('Production response size', () => {
)

// These numbers are without gzip compression!
const delta = responseSizeKilobytes - 228
const delta = responseSizeKilobytes - 234
expect(delta).toBeLessThanOrEqual(0) // don't increase size
expect(delta).toBeGreaterThanOrEqual(-1) // don't decrease size without updating target
})
Expand All @@ -101,7 +101,7 @@ describe('Production response size', () => {
)

// These numbers are without gzip compression!
const delta = responseSizeKilobytes - 196
const delta = responseSizeKilobytes - 203
expect(delta).toBeLessThanOrEqual(0) // don't increase size
expect(delta).toBeGreaterThanOrEqual(-1) // don't decrease size without updating target
})
Expand Down
7 changes: 0 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10079,13 +10079,6 @@ native-or-bluebird@^1.2.0:
resolved "https://registry.yarnpkg.com/native-or-bluebird/-/native-or-bluebird-1.2.0.tgz#39c47bfd7825d1fb9ffad32210ae25daadf101c9"
integrity sha1-OcR7/Xgl0fuf+tMiEK4l2q3xAck=

[email protected]:
version "0.2.4"
resolved "https://registry.yarnpkg.com/native-url/-/native-url-0.2.4.tgz#37623b3db2c7bb6670e50e379634248ba5ca9d90"
integrity sha512-McE+8BrgMw2ANypdYX9s1L+aUkbWDCEtsBGIbs8TfKBfQrFcZ2jMXX9LxGjOIOtoRXkwLTSlz38XHm8J3U6hgQ==
dependencies:
querystring "^0.2.0"

natural-compare@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
Expand Down

0 comments on commit eb3e6fb

Please sign in to comment.