Skip to content

Commit

Permalink
next-dev test runner: Check in and use webpack's chunk test cases (ve…
Browse files Browse the repository at this point in the history
…rcel/turborepo#212)

This commits webpack's chunk tests (test/cases/chunks) and skips those
that do not pass yet.

Test Plan: `cargo test -p next-dev -- --nocapture` and verify the
non-skipped tests run.
  • Loading branch information
wbinnssmith authored Aug 11, 2022
1 parent 1d8b74c commit 4778270
Show file tree
Hide file tree
Showing 112 changed files with 926 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright JS Foundation and other contributors

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
it("should not bundle context requires with asyncMode === 'weak'", function () {
var contextRequire = require.context('.', false, /two/, 'weak')
expect(function () {
contextRequire('./two')
}).toThrowError(/not available/)
})

it("should not bundle context requires with asyncMode === 'weak' using import.meta.webpackContext", function () {
const contextRequire = import.meta.webpackContext('.', {
recursive: false,
regExp: /two/,
mode: 'weak',
})
expect(function () {
contextRequire('./two')
}).toThrowError(/not available/)
})

it("should find module with asyncMode === 'weak' when required elsewhere", function () {
var contextRequire = require.context('.', false, /.+/, 'weak')
expect(contextRequire('./three')).toBe(3)
require('./three') // in a real app would be served as a separate chunk
})

it("should find module with asyncMode === 'weak' when required elsewhere (recursive)", function () {
var contextRequire = require.context('.', true, /.+/, 'weak')
expect(contextRequire('./dir/four')).toBe(4)
require('./dir/four') // in a real app would be served as a separate chunk
})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
it('should also work in a chunk', function (done) {
require.ensure([], function (require) {
var contextRequire = require.context('.', false, /two/)
expect(contextRequire('./two')).toBe(2)
var tw = 'tw'
expect(require('.' + '/' + tw + 'o')).toBe(2)
done()
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import leftHelix from './leftHelix'
import rightHelix from './rightHelix'

it('should import generate ensure function for this', () => {
return Promise.all([leftHelix.run(), rightHelix.run()])
})

export default {
leftHelix,
rightHelix,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import leftHelixPrime, { run } from './leftHelixPrime'

export default {
leftHelixPrime,
run,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import rightHelixPrime from './rightHelixPrime'

export function run() {
return import(/* webpackChunkName: "left" */ './leftHelix')
}

export default {
rightHelixPrime: () => rightHelixPrime,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import rightHelixPrime, { run } from './rightHelixPrime'

export default {
rightHelixPrime,
run,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import leftHelixPrime from './leftHelixPrime'

export function run() {
return import(/* webpackChunkName: "right" */ './rightHelix')
}

export default {
leftHelixPrime: () => leftHelixPrime,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'initialModuleDefault'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.default = 'other'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'initialModuleDefault'
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
it('should resolve when import existed chunk (#8626)', function (done) {
require.context('./dir-initial/')
const fileName = 'initialModule'
import(`./dir-initial/${fileName}`)
.then(({ default: m }) => {
expect(m).toBe('initialModuleDefault')
done()
})
.catch(done)
})

it('should resolve when import existed chunk with fake maps', function (done) {
require.context('./dir-initial-with-fake-map/')
const fileName = 'initialModule'
import(`./dir-initial-with-fake-map/${fileName}`)
.then(({ default: m }) => {
expect(m).toBe('initialModuleDefault')
done()
})
.catch(done)
})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
function testCase(load, done) {
load('two', 2, function () {
var sync = true
load('one', 1, function () {
expect(sync).toBe(false)
load('three', 3, function () {
var sync = true
load('two', 2, function () {
expect(sync).toBe(true)
done()
})
Promise.resolve()
.then(function () {})
.then(function () {})
.then(function () {
sync = false
})
})
})
Promise.resolve().then(function () {
sync = false
})
})
}

it('should be able to use expressions in import', function (done) {
function load(name, expected, callback) {
import('./dir/' + name)
.then(function (result) {
expect(result).toEqual(
nsObj({
default: expected,
}),
)
callback()
})
.catch(function (err) {
done(err)
})
}
testCase(load, done)
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
it('should be able to use import', function (done) {
import('./two')
.then(function (two) {
expect(two).toEqual(
nsObj({
default: 2,
}),
)
done()
})
.catch(function (err) {
done(err)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'a'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'b'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'c'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'd'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'a'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'a'
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const c = 'c'

export const d = 'd'

export const longnameforexport = 'longnameforexport'

export default 'default2'

export const usedExports = __webpack_exports_info__.usedExports
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const c = 'c'

export const d = 'd'

export default 'default2'

export const usedExports = __webpack_exports_info__.usedExports
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const a = 'a'

export const b = 'b'

export default 'default'

export const usedExports = __webpack_exports_info__.usedExports
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'a'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'b'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'c'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'd'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'a'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'b'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'c'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'd'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'a'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'b'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'c'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'd'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'a'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'b'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'c'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'd'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'a'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'b'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'c'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'd'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'a'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'b'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'c'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'd'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'a'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'b'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'c'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'a'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'b'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'c'
Loading

0 comments on commit 4778270

Please sign in to comment.