Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

fix: Handle function transforms when typescript is set #57

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const getBrowserifyOptions = async (entry, userBrowserifyOptions = {}, typescrip
}

const transform = browserifyOptions.transform
const hasTsifyTransform = transform.some(([name]) => name.includes('tsify'))
const hasTsifyTransform = transform.some((stage) => Array.isArray(stage) && stage[0].includes('tsify'))
const hastsifyPlugin = browserifyOptions.plugin.includes('tsify')

if (hasTsifyTransform || hastsifyPlugin) {
Expand All @@ -136,7 +136,7 @@ Please do one of the following:

browserifyOptions.extensions.push('.ts', '.tsx')
// remove babelify setting
browserifyOptions.transform = transform.filter(([name]) => !name.includes('babelify'))
browserifyOptions.transform = transform.filter((stage) => !Array.isArray(stage) || !stage[0].includes('babelify'))
// add typescript compiler
browserifyOptions.transform.push([
path.join(__dirname, './lib/simple_tsify'), {
Expand Down
15 changes: 15 additions & 0 deletions test/unit/index_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,21 @@ describe('browserify preprocessor', function () {
})
})

// Regression test for cypress-io/cypress-browserify-preprocessor#56
it('handles transforms defined as functions', function () {
this.createWriteStreamApi.on.withArgs('finish').yields()

const transform = [() => { }, {}]

this.options.browserifyOptions = { transform }

return this.run().then(() => {
transform.forEach((stage, stageIndex) => {
expect(browserify.lastCall.args[0].transform[stageIndex]).to.eql(stage)
})
})
})

it('removes babelify transform', function () {
this.createWriteStreamApi.on.withArgs('finish').yields()

Expand Down