diff --git a/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts b/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts index 788eb2b3200891..94a3dc24665101 100644 --- a/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts +++ b/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts @@ -6,12 +6,28 @@ test('default + named imports from cjs dep (react)', async () => { expect(await page.textContent('.cjs button')).toBe('count is 1') }) +test('named imports from webpacked cjs (phoenix)', async () => { + expect(await page.textContent('.cjs-phoenix')).toBe('ok') +}) + +test('default import from webpacked cjs (clipboard)', async () => { + expect(await page.textContent('.cjs-clipboard')).toBe('ok') +}) + test('dynamic imports from cjs dep (react)', async () => { expect(await page.textContent('.cjs-dynamic button')).toBe('count is 0') await page.click('.cjs-dynamic button') expect(await page.textContent('.cjs-dynamic button')).toBe('count is 1') }) +test('dynamic named imports from webpacked cjs (phoenix)', async () => { + expect(await page.textContent('.cjs-dynamic-phoenix')).toBe('ok') +}) + +test('dynamic default import from webpacked cjs (clipboard)', async () => { + expect(await page.textContent('.cjs-dynamic-clipboard')).toBe('ok') +}) + test('dedupe', async () => { expect(await page.textContent('.dedupe button')).toBe('count is 0') await page.click('.dedupe button') diff --git a/packages/playground/optimize-deps/cjs-dynamic.js b/packages/playground/optimize-deps/cjs-dynamic.js index 6fff0fdf8a8efc..dceffd811772d7 100644 --- a/packages/playground/optimize-deps/cjs-dynamic.js +++ b/packages/playground/optimize-deps/cjs-dynamic.js @@ -6,6 +6,16 @@ const React = (await import('react')).default const ReactDOM = await import('react-dom') + const clip = await import('clipboard') + if (typeof clip.default === 'function') { + document.querySelector('.cjs-dynamic-clipboard').textContent = 'ok' + } + + const { Socket } = await import('phoenix') + if (typeof Socket === 'function') { + document.querySelector('.cjs-dynamic-phoenix').textContent = 'ok' + } + function App() { const [count, setCount] = useState(0) diff --git a/packages/playground/optimize-deps/cjs.js b/packages/playground/optimize-deps/cjs.js index b016d04c6fa661..196d395edc30a2 100644 --- a/packages/playground/optimize-deps/cjs.js +++ b/packages/playground/optimize-deps/cjs.js @@ -3,6 +3,16 @@ // are not statically detectable by @rollup/plugin-commonjs. import React, { useState } from 'react' import ReactDOM from 'react-dom' +import { Socket } from 'phoenix' +import clip from 'clipboard' + +if (typeof clip === 'function') { + document.querySelector('.cjs-clipboard').textContent = 'ok' +} + +if (typeof Socket === 'function') { + document.querySelector('.cjs-phoenix').textContent = 'ok' +} function App() { const [count, setCount] = useState(0) diff --git a/packages/playground/optimize-deps/index.html b/packages/playground/optimize-deps/index.html index 182bbea32bb479..b45bdd61de446f 100644 --- a/packages/playground/optimize-deps/index.html +++ b/packages/playground/optimize-deps/index.html @@ -2,10 +2,20 @@