({
context,
files,
fixture,
options,
cwd,
expectDir = '.',
expectPattern,
beforeBuild,
snapshot: shouldSnapshot = true,
prettier,
}: TestBuildOptions)
| 115 | } |
| 116 | |
| 117 | export async function testBuild({ |
| 118 | context, |
| 119 | files, |
| 120 | fixture, |
| 121 | options, |
| 122 | cwd, |
| 123 | expectDir = '.', |
| 124 | expectPattern, |
| 125 | beforeBuild, |
| 126 | snapshot: shouldSnapshot = true, |
| 127 | prettier, |
| 128 | }: TestBuildOptions): Promise<{ |
| 129 | testName: string |
| 130 | testDir: string |
| 131 | outputFiles: string[] |
| 132 | outputDir: string |
| 133 | snapshot: string |
| 134 | fileMap: Record<string, string> |
| 135 | warnings: RollupLog[] |
| 136 | bundle: TsdownBundle[] |
| 137 | }> { |
| 138 | const { expect } = context |
| 139 | const { testName, testDir } = await writeFixtures(context, files, fixture) |
| 140 | |
| 141 | const workingDir = path.join(testDir, cwd || '.') |
| 142 | const restoreCwd = chdir(workingDir) |
| 143 | const warnings: RollupLog[] = [] |
| 144 | const userOptions = |
| 145 | typeof options === 'function' ? options(workingDir) : options |
| 146 | const resolvedOptions: InlineConfig = { |
| 147 | entry: 'index.ts', |
| 148 | config: false, |
| 149 | outDir: 'dist', |
| 150 | dts: false, |
| 151 | logLevel: 'silent', |
| 152 | tsconfig: false, |
| 153 | failOnWarn: false, |
| 154 | ...userOptions, |
| 155 | async inputOptions(options, ...args) { |
| 156 | const originalOnLog = options.onLog |
| 157 | options = await mergeUserOptions( |
| 158 | { |
| 159 | ...options, |
| 160 | onLog(level, log, defaultHandler) { |
| 161 | if (level === 'warn') { |
| 162 | warnings.push(log) |
| 163 | } |
| 164 | const _defaultHandler: LogOrStringHandler = (level, ...args) => { |
| 165 | if (level !== 'error') return |
| 166 | defaultHandler(level, ...args) |
| 167 | } |
| 168 | if (originalOnLog) { |
| 169 | originalOnLog(level, log, _defaultHandler) |
| 170 | } else { |
| 171 | _defaultHandler(level, log) |
| 172 | } |
| 173 | }, |
| 174 | logLevel: 'info', |
no test coverage detected
searching dependent graphs…