Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in 2.1.2: a transform must export a process or processAsync function. #74

Closed
rmunn opened this issue Sep 13, 2021 · 9 comments · Fixed by #75
Closed

Regression in 2.1.2: a transform must export a process or processAsync function. #74

rmunn opened this issue Sep 13, 2021 · 9 comments · Fixed by #75

Comments

@rmunn
Copy link

rmunn commented Sep 13, 2021

Just updated svelte-jester from 2.1.1 to 2.1.2 and now my tests won't run. "TypeError: Jest: a transform must export a process or processAsync function." Reverting back to 2.1.1 makes the tests run again.

I inserted some console.log calls into the loadTransformers() function from jest-transform and found that it ran three times. The first two times, it went through this block, but the third time it didn't:

if (typeof transformer.createTransformer === 'function') {
  transformer = transformer.createTransformer(transformerConfig);
}

I inserted console.log(transformer) calls before and after that block, and got the following:

First pass

Before:

{
  canInstrument: true,
  getCacheKey: [Function: getCacheKey],
  getCacheKeyAsync: [AsyncFunction: getCacheKeyAsync],
  process: [Function: process],
  processAsync: [AsyncFunction: processAsync],
  createTransformer: [Function: createTransformer]
}

After:

{
  canInstrument: true,
  getCacheKey: [Function: getCacheKey],
  getCacheKeyAsync: [AsyncFunction: getCacheKeyAsync],
  process: [Function: process],
  processAsync: [AsyncFunction: processAsync]
}

Second pass

Before:

{ createTransformer: [Function: createTransformer] }

After:

TsJestTransformer {
  _depGraphs: Map(0) {},
  _watchMode: false,
  _logger: [Function: log] {
    child: [Function (anonymous)],
    wrap: [Function (anonymous)],
    trace: [Function (anonymous)],
    debug: [Function: emptyFunction],
    info: [Function (anonymous)],
    warn: [Function (anonymous)],
    error: [Function (anonymous)],
    fatal: [Function (anonymous)]
  },
  getCacheKey: [Function: bound ],
  process: [Function: bound ]
}

Third pass

Before:

[Function: createTransformer]

After:

[Function: createTransformer]

I don't know why on the third pass, the transformer value is the createTransformer function instead of having a createTrasnformer property (i.e. it should be { createTransformer: [Function: createTransformer] } at that point). Being unfamiliar with the Jest code base, that's as far as I can get easily. But hopefully this will give you some idea of what part of the code might be causing this regression.

@rmunn
Copy link
Author

rmunn commented Sep 13, 2021

Reproduction steps:

  • Run npm init svelte@next
  • Edit tsconfig.json to remove comments (so npx apply rossyman/svelte-add-jest won't throw)
  • Run npx apply rossyman/svelte-add-jest
  • Run npm install
  • Run npm run test and see the exception that Jest throws

@sebastianrothe
Copy link
Collaborator

I will add some tests that mimic the usual usage to get this covered, finally.

@rmunn
Copy link
Author

rmunn commented Sep 14, 2021

Can confirm that #75 fixes this issue for me.

@schicks
Copy link

schicks commented Sep 14, 2021

This does not appear to be released yet. When can we expect a 2.1.3 with this fix? Right now we're using jest 25 because we can't get 27 to work until this is out.

@jakobrosenberg
Copy link

For anyone else waiting for 2.1.3, I cloned and published the master branch to svelte-jester-pre-fix. To use it you can temporarily add "svelte-jester": "npm:svelte-jester-pre-fix@^2.1.3" to your devDependencies until the official 2.1.3 has been released.

It has fixed all issues for me but YMMV.

@mihar-22
Copy link
Collaborator

Sorry about the delay, released 2.1.3!

@asode
Copy link

asode commented Sep 19, 2021

Thank you for the update! However, still having some issues: though not sure if I'm the only one, but still getting an error about the preprocess.js file:

 FAIL  src/components/Layout.test.ts
  ● Test suite failed to run

    Cannot find module './preprocess.js'
    Require stack:
    - /home/asode/coding/my-svelte-vite-test/node_modules/svelte-jester/dist/transformer.cjs
    - /home/asode/coding/my-svelte-vite-test/node_modules/jest-util/build/requireOrImportModule.js
    - /home/asode/coding/my-svelte-vite-test/node_modules/jest-util/build/index.js
    - /home/asode/coding/my-svelte-vite-test/node_modules/@jest/core/build/cli/index.js
    - /home/asode/coding/my-svelte-vite-test/node_modules/@jest/core/build/jest.js
    - /home/asode/coding/my-svelte-vite-test/node_modules/jest-cli/build/cli/index.js
    - /home/asode/coding/my-svelte-vite-test/node_modules/jest-cli/bin/jest.js
    - /home/asode/coding/my-svelte-vite-test/node_modules/jest/bin/jest.js

    Require stack:
      node_modules/svelte-jester/dist/transformer.cjs
      node_modules/jest-util/build/requireOrImportModule.js
      node_modules/jest-util/build/index.js
      node_modules/@jest/core/build/cli/index.js
      node_modules/@jest/core/build/jest.js
      node_modules/jest-cli/build/cli/index.js
      node_modules/jest-cli/bin/jest.js
      node_modules/jest/bin/jest.js

      at Object.processSync [as process] (node_modules/svelte-jester/dist/transformer.cjs:115:32)
      at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:612:31)
      at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:758:40)
      at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:815:19)
  "devDependencies": {
    "@sveltejs/vite-plugin-svelte": "^1.0.0-next.24",
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/svelte": "^3.0.3",
    "@tsconfig/svelte": "^2.0.1",
    "@types/cssnano": "^4.0.1",
    "@types/jest": "^27.0.1",
    "@typescript-eslint/eslint-plugin": "^4.31.1",
    "@typescript-eslint/parser": "^4.31.1",
    "autoprefixer": "^10.3.4",
    "cssnano": "^5.0.8",
    "eslint-plugin-svelte3": "^3.2.1",
    "jest": "^27.2.0",
    "postcss": "^8.3.6",
    "postcss-load-config": "^3.1.0",
    "svelte": "^3.42.6",
    "svelte-check": "^2.2.6",
    "svelte-jester": "^2.1.3",
    "svelte-navigator": "^3.1.5",
    "svelte-preprocess": "^4.9.4",
    "tailwindcss": "^2.2.15",
    "ts-jest": "^27.0.5",
    "ts-node": "^10.2.1",
    "tslib": "^2.3.1",
    "typescript": "^4.4.3",
    "vite": "^2.5.10"
  }

@schicks
Copy link

schicks commented Sep 20, 2021

I'm also getting that issue. When I look in the svelte-jester folder in node modules it appears that the preprocess file is missing; there's just a transformer.cjs and a transformer.mjs file in the dist directory. Is it possible that something went wrong in the build process when publishing v2.1.3?

@sebastianrothe
Copy link
Collaborator

Yeah, sorry about that. Will be fixed, see #81

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants