Skip to content

Commit b0c1d85

Browse files
committed
Fix build tests
1 parent 2dad262 commit b0c1d85

File tree

6 files changed

+119
-107
lines changed

6 files changed

+119
-107
lines changed

examples/data.ts

+19-19
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ const JS_TEMPLATES: Template[] = [
2020
hasEnv: false,
2121
configFiles: undefined
2222
},
23-
{
24-
name: 'content',
25-
uiContext: ['content'],
26-
uiFramework: undefined,
27-
css: 'css',
28-
hasBackground: false,
29-
hasEnv: false,
30-
configFiles: undefined
31-
},
23+
// {
24+
// name: 'content',
25+
// uiContext: ['content'],
26+
// uiFramework: undefined,
27+
// css: 'css',
28+
// hasBackground: false,
29+
// hasEnv: false,
30+
// configFiles: undefined
31+
// },
3232
// {
3333
// name: 'content-esm',
3434
// uiContext: ['content'],
@@ -356,15 +356,15 @@ const FRAMEWORK_TEMPLATES: Template[] = [
356356
hasEnv: false,
357357
configFiles: ['tsconfig.json']
358358
},
359-
// {
360-
// name: 'content-vue',
361-
// uiContext: ['content'],
362-
// uiFramework: 'vue',
363-
// css: 'css',
364-
// hasBackground: false,
365-
// hasEnv: false,
366-
// configFiles: ['postcss.config.js', 'tailwind.config.js', 'tsconfig.json']
367-
// },
359+
{
360+
name: 'content-vue',
361+
uiContext: ['content'],
362+
uiFramework: 'vue',
363+
css: 'css',
364+
hasBackground: false,
365+
hasEnv: false,
366+
configFiles: ['postcss.config.js', 'tailwind.config.js', 'tsconfig.json']
367+
},
368368
{
369369
name: 'new-svelte',
370370
uiContext: ['newTab'],
@@ -449,7 +449,7 @@ const CONFIG_TEMPLATES: Template[] = [
449449
]
450450

451451
const ALL_TEMPLATES: Template[] = [
452-
DEFAULT_TEMPLATE,
452+
// DEFAULT_TEMPLATE,
453453
...JS_TEMPLATES,
454454
...WASM_TEMPLATES,
455455
...TS_TEMPLATES,

examples/sidebar-shadcn/sidebar/styles.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@
7272

7373
@layer base {
7474
#root * {
75-
@apply border-border;
75+
@apply border;
7676
}
7777

7878
#root {
79-
@apply bg-background text-foreground h-screen;
79+
@apply h-screen;
8080
font-feature-settings:
8181
'rlig' 1,
8282
'calt' 1;

programs/develop/build.spec.ts

+86-64
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,22 @@ function distFileExists(
5757
}
5858

5959
describe('extension build', () => {
60+
afterAll(async () => {
61+
// Clean up any mocks
62+
jest.clearAllMocks()
63+
// Clean up any remaining test artifacts
64+
await removeAllTemplateDistFolders()
65+
// Clear all timers
66+
jest.useRealTimers()
67+
// Clear any hanging handles
68+
await new Promise(resolve => setTimeout(resolve, 0))
69+
// Force garbage collection if available
70+
if (global.gc) global.gc()
71+
}, 30000)
72+
6073
beforeEach(async () => {
74+
// Reset timers before each test
75+
jest.useRealTimers()
6176
await removeAllTemplateDistFolders()
6277
}, 30000)
6378

@@ -75,75 +90,77 @@ describe('extension build', () => {
7590

7691
const postCssConfig = path.join(templatePath, 'postcss.config.js')
7792

78-
// Dynamically mock the postcss.config.js file if it exists.
79-
// Since the file is dynamically imported in the webpack config,
80-
// we need to mock it before the webpack config is created.
81-
if (fs.existsSync(postCssConfig)) {
82-
jest.mock(postCssConfig, () => jest.fn())
83-
}
84-
85-
await extensionBuild(templatePath, {
86-
browser: SUPPORTED_BROWSERS[0] as 'chrome'
87-
})
88-
89-
expect(
90-
path.join(
91-
templatePath,
92-
'dist',
93-
SUPPORTED_BROWSERS[0],
94-
'manifest.json'
95-
)
96-
).toBeTruthy()
97-
98-
const manifestText = fs.readFileSync(
99-
path.join(
100-
templatePath,
101-
'dist',
102-
SUPPORTED_BROWSERS[0],
103-
'manifest.json'
104-
),
105-
'utf-8'
106-
)
93+
try {
94+
// Dynamically mock the postcss.config.js file if it exists
95+
if (fs.existsSync(postCssConfig)) {
96+
jest.mock(postCssConfig, () => jest.fn())
97+
}
10798

108-
const manifest: Manifest = JSON.parse(manifestText)
109-
expect(manifest.name).toBeTruthy
110-
expect(manifest.version).toBeTruthy
111-
expect(manifest.manifest_version).toBeTruthy
99+
await extensionBuild(templatePath, {
100+
browser: SUPPORTED_BROWSERS[0] as 'chrome'
101+
})
112102

113-
if (template.name.includes('content')) {
114-
// Since extension@2.0.0-beta-6, the content script is injected
115-
// into the shadow DOM. Including in production mode.
116-
// expect(manifest.content_scripts![0].css![0]).toEqual(
117-
// 'content_scripts/content-0.css'
118-
// )
103+
expect(
104+
path.join(
105+
templatePath,
106+
'dist',
107+
SUPPORTED_BROWSERS[0],
108+
'manifest.json'
109+
)
110+
).toBeTruthy()
119111

120-
expect(manifest.content_scripts![0].js![0]).toEqual(
121-
'content_scripts/content-0.js'
112+
const manifestText = fs.readFileSync(
113+
path.join(
114+
templatePath,
115+
'dist',
116+
SUPPORTED_BROWSERS[0],
117+
'manifest.json'
118+
),
119+
'utf-8'
122120
)
123121

124-
// Since extension@2.0.0-beta-6, the content script is injected
125-
// into the shadow DOM. Including in production mode.
126-
// expect(
127-
// distFileExists(
128-
// template.name,
129-
// SUPPORTED_BROWSERS[0],
130-
// 'content_scripts/content-0.css'
131-
// )
132-
// ).toBeTruthy()
122+
const manifest: Manifest = JSON.parse(manifestText)
123+
expect(manifest.name).toBeTruthy()
124+
expect(manifest.version).toBeTruthy()
125+
expect(manifest.manifest_version).toBeTruthy()
133126

134-
expect(
135-
distFileExists(
136-
template.name,
137-
SUPPORTED_BROWSERS[0],
127+
if (template.name.includes('content')) {
128+
expect(manifest.content_scripts![0].js![0]).toEqual(
138129
'content_scripts/content-0.js'
139130
)
140-
).toBeTruthy()
131+
expect(
132+
distFileExists(
133+
template.name,
134+
SUPPORTED_BROWSERS[0],
135+
'content_scripts/content-0.css'
136+
)
137+
).toBeTruthy()
138+
139+
expect(
140+
distFileExists(
141+
template.name,
142+
SUPPORTED_BROWSERS[0],
143+
'content_scripts/content-0.js'
144+
)
145+
).toBeTruthy()
146+
147+
}
148+
} finally {
149+
// Clean up mocks after each test
150+
if (fs.existsSync(postCssConfig)) {
151+
jest.unmock(postCssConfig)
152+
}
141153
}
142154
},
143155
80000
144156
)
145157
})
146158

159+
afterEach(async () => {
160+
jest.clearAllTimers()
161+
await new Promise(resolve => setImmediate(resolve))
162+
})
163+
147164
describe('using the --browser flag', () => {
148165
it.each(ALL_TEMPLATES)(
149166
`builds the "$name" extension template across all supported browsers`,
@@ -157,16 +174,21 @@ describe('extension build', () => {
157174
)
158175

159176
// Running browsers in parallel by invoking them sequentially
160-
await Promise.all(
161-
SUPPORTED_BROWSERS.filter((browser) => browser !== 'chrome').map(
162-
async (browser) => {
163-
await extensionBuild(templatePath, {browser: browser as any})
164-
expect(
165-
path.join(templatePath, SUPPORTED_BROWSERS[0], 'manifest.json')
166-
).toBeTruthy()
167-
}
177+
try {
178+
await Promise.all(
179+
SUPPORTED_BROWSERS.filter((browser) => browser !== 'chrome').map(
180+
async (browser) => {
181+
await extensionBuild(templatePath, {browser: browser as any})
182+
expect(
183+
path.join(templatePath, SUPPORTED_BROWSERS[0], 'manifest.json')
184+
).toBeTruthy()
185+
}
186+
)
168187
)
169-
)
188+
} finally {
189+
// Ensure promises are settled
190+
await new Promise(resolve => setImmediate(resolve))
191+
}
170192
},
171193
80000
172194
)

programs/develop/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"compile": "tsup-node ./module.ts --format cjs --dts --target=node18 --minify && bash install_scripts.sh",
2828
"test": "jest --no-cache --testPathPattern='webpack/.*/__spec__/.*\\.spec\\.*'",
2929
"test:coverage": "jest --no-cache --testPathPattern='webpack/.*/__spec__/.*\\.spec\\.ts' --coverage",
30-
"test:build": "jest ./build.spec.ts --no-cache"
30+
"test:build": "jest ./build.spec.ts --no-cache --detectOpenHandles --forceExit"
3131
},
3232
"dependencies": {
3333
"@colors/colors": "^1.6.0",

programs/develop/webpack/plugin-js-frameworks/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class JsFrameworksPlugin {
2828
const maybeInstallBabel = await maybeUseBabel(compiler, projectPath)
2929
const maybeInstallReact = await maybeUseReact(projectPath)
3030
const maybeInstallPreact = await maybeUsePreact(projectPath)
31-
const maybeInstallVue = await maybeUseVue(projectPath)
31+
const maybeInstallVue = await maybeUseVue(projectPath, mode as any)
3232
const maybeInstallSvelte = await maybeUseSvelte(projectPath, mode as any)
3333

3434
compiler.options.resolve.alias = {

programs/develop/webpack/plugin-js-frameworks/js-tools/vue.ts

+10-20
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import path from 'path'
99
import fs from 'fs'
10+
import { VueLoaderPlugin } from 'vue-loader';
1011
import * as messages from '../../lib/messages'
1112
import {installOptionalDependencies} from '../../lib/utils'
1213
import {JsFramework} from '../../webpack-types'
@@ -39,27 +40,18 @@ export function isUsingVue(projectPath: string) {
3940
}
4041

4142
export async function maybeUseVue(
42-
projectPath: string
43+
projectPath: string,
44+
mode: 'development' | 'production'
4345
): Promise<JsFramework | undefined> {
4446
if (!isUsingVue(projectPath)) return undefined
4547

4648
try {
4749
require.resolve('vue-loader')
4850
} catch (e) {
49-
const typeScriptDependencies = ['typescript']
50-
51-
await installOptionalDependencies('TypeScript', typeScriptDependencies)
52-
53-
const vueDependencies = [
54-
'vue-loader',
55-
'vue-template-compiler',
56-
'vue-style-loader'
57-
]
51+
const vueDependencies = ['vue-loader', 'vue-template-compiler']
5852

5953
await installOptionalDependencies('Vue', vueDependencies)
6054

61-
// The compiler will exit after installing the dependencies
62-
// as it can't read the new dependencies without a restart.
6355
console.log(messages.youAreAllSet('Vue'))
6456
process.exit(0)
6557
}
@@ -68,19 +60,17 @@ export async function maybeUseVue(
6860
{
6961
test: /\.vue$/,
7062
loader: require.resolve('vue-loader'),
71-
include: projectPath,
72-
exclude: [/[\\/]node_modules[\\/]/],
7363
options: {
74-
// Note, for the majority of features to be available,
75-
// make sure this option is `true`.
76-
// https://rspack.dev/guide/tech/vue#vue-3
77-
experimentalInlineMatchResource: true
78-
}
64+
// Note, for the majority of features to be available, make sure this option is `true`
65+
experimentalInlineMatchResource: true,
66+
},
67+
include: projectPath,
68+
exclude: /node_modules/
7969
}
8070
]
8171

8272
const vuePlugins: JsFramework['plugins'] = [
83-
new (require('vue-loader').VueLoaderPlugin)()
73+
new VueLoaderPlugin() as any
8474
]
8575

8676
return {

0 commit comments

Comments
 (0)