-
Notifications
You must be signed in to change notification settings - Fork 27.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #4686 Adds tests for @zeit/next-typescript so that we don't regress on this again. I've fixed an issue in the `next` CLI too which caused lingering processes when the process gets force killed, which is what we do in the test suite, so it kept running if there was no manual quit.
- Loading branch information
1 parent
810705a
commit 17e410a
Showing
16 changed files
with
158 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"presets": [ | ||
"next/babel", | ||
"@zeit/next-typescript/babel" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const withTypescript = require('@zeit/next-typescript') | ||
module.exports = withTypescript({ | ||
onDemandEntries: { | ||
// Make sure entries are not getting disposed. | ||
maxInactiveAge: 1000 * 60 * 60 | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react' | ||
|
||
if(typeof window !== 'undefined' && !window['HMR_RANDOM_NUMBER']) { | ||
window['HMR_RANDOM_NUMBER'] = Math.random() | ||
} | ||
|
||
export default class Counter extends React.Component { | ||
state = { count: 0 } | ||
|
||
incr () { | ||
const { count } = this.state | ||
this.setState({ count: count + 1 }) | ||
} | ||
|
||
render () { | ||
return ( | ||
<div> | ||
<p>COUNT: {this.state.count}</p> | ||
<button onClick={() => this.incr()}>Increment</button> | ||
</div> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"presets": [ | ||
["next/babel", { | ||
"preset-env": { | ||
"modules": "commonjs" | ||
} | ||
}] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* global describe, it, expect */ | ||
import webdriver from 'next-webdriver' | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
timneutkens
Author
Member
|
||
import { readFileSync, writeFileSync } from 'fs' | ||
import { join } from 'path' | ||
import { waitFor } from 'next-test-utils' | ||
|
||
export default (context, renderViaHTTP) => { | ||
describe('Hot Module Reloading', () => { | ||
it('should reload typescript file without refresh', async () => { | ||
let browser | ||
const pagePath = join(__dirname, '../', 'pages', 'hmr', 'some-page.tsx') | ||
|
||
const originalContent = readFileSync(pagePath, 'utf8') | ||
const editedContent = originalContent.replace('Increment', 'INCREMENT') | ||
try { | ||
browser = await webdriver(context.appPort, '/hmr/some-page') | ||
const randomNumber = await browser.eval('window.HMR_RANDOM_NUMBER') | ||
const originalButtonText = await browser.elementByCss('button').text() | ||
expect(originalButtonText).toBe('Increment') | ||
|
||
// Change the about.js page | ||
writeFileSync(pagePath, editedContent, 'utf8') | ||
|
||
// wait for 5 seconds | ||
await waitFor(5000) | ||
|
||
const randomNumberAfterEdit = await browser.eval('window.HMR_RANDOM_NUMBER') | ||
expect(randomNumberAfterEdit).toBe(randomNumber) | ||
const updatedButtonText = await browser.elementByCss('button').text() | ||
expect(updatedButtonText).toBe('INCREMENT') | ||
} finally { | ||
// restore the about page content. | ||
writeFileSync(pagePath, originalContent, 'utf8') | ||
if (browser) { | ||
browser.close() | ||
} | ||
} | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* global jasmine, describe, beforeAll, afterAll */ | ||
|
||
import { join } from 'path' | ||
import { | ||
renderViaHTTP, | ||
findPort, | ||
launchApp, | ||
killApp | ||
} from 'next-test-utils' | ||
|
||
// test suits | ||
import hmr from './hmr' | ||
|
||
const context = {} | ||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5 | ||
|
||
describe('Page Extensions', () => { | ||
beforeAll(async () => { | ||
context.appPort = await findPort() | ||
context.server = await launchApp(join(__dirname, '../'), context.appPort) | ||
|
||
// pre-build all pages at the start | ||
await Promise.all([ | ||
renderViaHTTP(context.appPort, '/hmr/some-page') | ||
]) | ||
}) | ||
afterAll(() => killApp(context.server)) | ||
|
||
hmr(context, (p, q) => renderViaHTTP(context.appPort, p, q)) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -349,6 +349,12 @@ | |
dependencies: | ||
"@babel/helper-plugin-utils" "7.0.0-beta.42" | ||
|
||
"@babel/[email protected]": | ||
version "7.0.0-beta.42" | ||
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.0.0-beta.42.tgz#ffc42945ca15e5ab369de6b9f5d9324499c623cf" | ||
dependencies: | ||
"@babel/helper-plugin-utils" "7.0.0-beta.42" | ||
|
||
"@babel/[email protected]": | ||
version "7.0.0-beta.42" | ||
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-arrow-functions/-/plugin-transform-arrow-functions-7.0.0-beta.42.tgz#b918eb8760c38d6503a1a9858fa073786b60ab2b" | ||
|
@@ -571,6 +577,13 @@ | |
dependencies: | ||
"@babel/helper-plugin-utils" "7.0.0-beta.42" | ||
|
||
"@babel/[email protected]": | ||
version "7.0.0-beta.42" | ||
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.0.0-beta.42.tgz#e3a2d46014fd26e0729fd574b521fca4eb21144f" | ||
dependencies: | ||
"@babel/helper-plugin-utils" "7.0.0-beta.42" | ||
"@babel/plugin-syntax-typescript" "7.0.0-beta.42" | ||
|
||
"@babel/[email protected]": | ||
version "7.0.0-beta.42" | ||
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-unicode-regex/-/plugin-transform-unicode-regex-7.0.0-beta.42.tgz#1e7bdcf678d9a9066d06e6d334ab41ca11ca00ad" | ||
|
@@ -641,6 +654,13 @@ | |
"@babel/plugin-transform-react-jsx-self" "7.0.0-beta.42" | ||
"@babel/plugin-transform-react-jsx-source" "7.0.0-beta.42" | ||
|
||
"@babel/[email protected]": | ||
version "7.0.0-beta.42" | ||
resolved "https://registry.yarnpkg.com/@babel/preset-typescript/-/preset-typescript-7.0.0-beta.42.tgz#adb91d387a6eee7b45918de544d6c8fa122c2564" | ||
dependencies: | ||
"@babel/helper-plugin-utils" "7.0.0-beta.42" | ||
"@babel/plugin-transform-typescript" "7.0.0-beta.42" | ||
|
||
"@babel/[email protected]": | ||
version "7.0.0-beta.42" | ||
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.0.0-beta.42.tgz#352e40c92e0460d3e82f49bd7e79f6cda76f919f" | ||
|
@@ -751,6 +771,12 @@ | |
postcss-loader "^2.0.10" | ||
style-loader "^0.19.1" | ||
|
||
"@zeit/[email protected]": | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/@zeit/next-typescript/-/next-typescript-1.1.0.tgz#57a45c85c336fee8d71c1bd966195565016932b2" | ||
dependencies: | ||
"@babel/preset-typescript" "7.0.0-beta.42" | ||
|
||
abab@^1.0.3: | ||
version "1.0.4" | ||
resolved "https://registry.yarnpkg.com/abab/-/abab-1.0.4.tgz#5faad9c2c07f60dd76770f71cf025b62a63cfd4e" | ||
|
Wow this.. this is some hardcore work Tim. 💪