Skip to content

Commit e2d14de

Browse files
authoredApr 11, 2022
fix: run compiled tests (#961)
In order to not have to declare browser overrides for both `src` and `dist`, run tests on the compiled test output for ts projects.
1 parent 1883dfc commit e2d14de

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed
 

‎src/build/index.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import path from 'path'
66
import fs from 'fs-extra'
77
import pascalcase from 'pascalcase'
88
import bytes from 'bytes'
9-
import { gzipSize, pkg, hasTsconfig, hasFile, fromRoot, paths } from './../utils.js'
9+
import { gzipSize, pkg, hasTsconfig, isTypescript, fromRoot, paths } from './../utils.js'
1010
import { execa } from 'execa'
1111
import merge from 'merge-options'
1212

@@ -30,10 +30,11 @@ const build = async (argv) => {
3030
const globalName = pascalcase(pkg.name)
3131
const umdPre = `(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.${globalName} = factory()}(typeof self !== 'undefined' ? self : this, function () {`
3232
const umdPost = `return ${globalName}}));`
33+
let entryPoint = fromRoot('src', 'index.js')
3334

34-
const tsIndex = fromRoot('src', 'index.ts')
35-
const jsIndex = fromRoot('src', 'index.js')
36-
const entryPoint = hasFile(tsIndex) ? tsIndex : jsIndex
35+
if (isTypescript) {
36+
entryPoint = fromRoot('dist', 'src', 'index.js')
37+
}
3738

3839
const result = await esbuild.build(defaults(
3940
{

‎src/test/browser.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ export default async (argv, execaOptions) => {
3030
const files = argv.files.length > 0
3131
? argv.files
3232
: [
33-
'test/**/*.spec.{js,ts,cjs,mjs}',
34-
'test/browser.{js,ts,cjs,mjs}'
33+
'test/**/*.spec.{js,cjs,mjs}',
34+
'test/browser.{js,cjs,mjs}',
35+
'dist/test/**/*.spec.{js,cjs,mjs}',
36+
'dist/test/browser.{js,cjs,mjs}'
3537
]
3638

3739
// before hook

‎src/test/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const TASKS = [
2626
* @param {BuildOptions & GlobalOptions} ctx
2727
*/
2828
task: async (ctx) => {
29-
await execa('npm', ['run', 'build', '--if-present'], {
29+
await execa('npm', ['run', 'build', '--if-present', '--', '--no-bundle'], {
3030
stdio: 'inherit'
3131
})
3232
}

0 commit comments

Comments
 (0)
Please sign in to comment.