forked from nocobase/nocobase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create nocobase app unit test (nocobase#3833)
* fix: unit test package bug * fix: client esm * fix: nocobase test e2e esm format (T-2824)
- Loading branch information
Showing
11 changed files
with
87 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
|
||
import path from 'path'; | ||
import { PkgLog, UserConfig } from './utils'; | ||
import { build as viteBuild } from 'vite'; | ||
import fg from 'fast-glob'; | ||
|
||
export async function buildEsm(cwd: string, userConfig: UserConfig, sourcemap: boolean = false, log: PkgLog) { | ||
log('build esm'); | ||
|
||
const indexEntry = path.join(cwd, 'src/index.ts').replaceAll(/\\/g, '/'); | ||
const outDir = path.resolve(cwd, 'es'); | ||
|
||
await build(cwd, indexEntry, outDir, userConfig, sourcemap, log); | ||
|
||
const clientEntry = fg.sync(['src/client/index.ts', 'src/client.ts'], { cwd, absolute: true, onlyFiles: true })?.[0]?.replaceAll(/\\/g, '/'); | ||
const clientOutDir = path.resolve(cwd, 'es/client'); | ||
if (clientEntry) { | ||
await build(cwd, clientEntry, clientOutDir, userConfig, sourcemap, log); | ||
} | ||
|
||
const pkg = require(path.join(cwd, 'package.json')); | ||
if (pkg.name === '@nocobase/test') { | ||
const e2eEntry = path.join(cwd, 'src/e2e/index.ts').replaceAll(/\\/g, '/'); | ||
const e2eOutDir = path.resolve(cwd, 'es/e2e'); | ||
await build(cwd, e2eEntry, e2eOutDir, userConfig, sourcemap, log); | ||
} | ||
} | ||
|
||
function build(cwd: string, entry: string, outDir: string, userConfig: UserConfig, sourcemap: boolean = false, log: PkgLog) { | ||
const cwdWin = cwd.replaceAll(/\\/g, '/'); | ||
const cwdUnix = cwd.replaceAll(/\//g, '\\'); | ||
const external = function (id: string) { | ||
if (id.startsWith('.') || id.startsWith(cwdUnix) || id.startsWith(cwdWin)) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
return viteBuild( | ||
userConfig.modifyViteConfig({ | ||
mode: process.env.NODE_ENV || 'production', | ||
define: { | ||
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production'), | ||
'process.env.__TEST__': false, | ||
'process.env.__E2E__': process.env.__E2E__ ? true : false, | ||
}, | ||
build: { | ||
minify: false, | ||
outDir, | ||
cssCodeSplit: true, | ||
emptyOutDir: true, | ||
sourcemap, | ||
lib: { | ||
entry, | ||
formats: ['es'], | ||
fileName: 'index', | ||
}, | ||
target: ['node16'], | ||
rollupOptions: { | ||
cache: true, | ||
treeshake: true, | ||
external, | ||
}, | ||
}, | ||
}), | ||
); | ||
} |
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
2 changes: 1 addition & 1 deletion
2
packages/core/create-nocobase-app/templates/app/vitest.config.mts
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { defineConfig } from '@nocobase/test'; | ||
import { defineConfig } from '@nocobase/test/vitest.mjs'; | ||
|
||
export default defineConfig(); |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,2 +1 @@ | ||
export * from './defineConfig'; | ||
export * from './server'; |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { defineConfig } from '@nocobase/test'; | ||
import { defineConfig } from '@nocobase/test/vitest.mjs'; | ||
|
||
export default defineConfig(); |