Commit 874b5338 authored by JJ Kasper's avatar JJ Kasper Committed by Joe Haddad

Add tests for typeof window replacing (#8361)

* Add tests for typeof window replacing

* Update test for typeof window replace from a node_module
parent 5a8ed815
const react = require('react')
module.exports = function() {
return react.createElement('p', null, 'MyComp:', typeof window)
}
{
"name": "comps",
"version": "1.0.0",
"main": "index.js",
"license": "MIT"
}
{
"name": "app",
"version": "1.0.0",
"main": "index.js",
"license": "MIT"
}
import MyComp from 'comps'
const Page = () => (
<>
<p>Hello {typeof window}</p>
<MyComp />
</>
)
Page.getInitialProps = () => ({})
export default Page
/* eslint-env jest */
/* global jasmine */
import fs from 'fs-extra'
import path from 'path'
import { nextBuild } from 'next-test-utils'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 1
const appDir = path.join(__dirname, '../app')
let buildId
describe('typeof window replace', () => {
beforeAll(async () => {
await nextBuild(appDir)
buildId = await fs.readFile(path.join(appDir, '.next/BUILD_ID'), 'utf8')
})
it('Replaces `typeof window` with object for client code', async () => {
const content = await fs.readFile(
path.join(appDir, '.next/static/', buildId, 'pages/index.js'),
'utf8'
)
expect(content).toMatch(/Hello.*?,.*?("|')object("|')/)
})
it('Replaces `typeof window` with undefined for server code', async () => {
const content = await fs.readFile(
path.join(appDir, '.next/server/static', buildId, 'pages/index.js'),
'utf8'
)
expect(content).toMatch(/Hello.*?,.*?("|')undefined("|')/)
})
it('Does not replace `typeof window` for `node_modules` code', async () => {
const content = await fs.readFile(
path.join(appDir, '.next/static/', buildId, 'pages/index.js'),
'utf8'
)
expect(content).toMatch(/MyComp:.*?,.*?typeof window/)
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment