Skip to content

using esbuild #399

Open
Open
@Ti-webdev

Description

@Ti-webdev

I found a way to run @vue/vue2-jest with esbuild

jest.config.js:

const esJest = require('./esJest.js')

module.exports = {
  testEnvironment: 'jest-environment-jsdom',
  transform: {
    '^.+\\.js$': './esJest.js',
    '^.+\\.vue$': '@vue/vue2-jest'
  },
  globals: {
    'vue-jest': {
      transform: {
        'js': esJest
      }
    }
  },
}

esJest.js:

const path = require('path')
const { transformSync } = require('esbuild')
const loaders = ['js', 'jsx', 'ts', 'tsx']
const target = `node${process.versions.node}`

exports.process = function (code, sourcefile) {
  const extname = path.extname(sourcefile)
  const loader = loaders.find((x) => `.${x}` === extname) || 'js'
  const options = {
    target,
    loader,
    sourcefile,
    format: 'cjs',
    sourcemap: 'external',
  }
  return transformSync(code, options)
}

but we still have dependencies to babel from @vue/vue2-jest as default...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions