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

ApiDataFactory with typescript factory file and ES6 export #3469

Closed
dwentland24 opened this issue Oct 22, 2022 · 0 comments · Fixed by #3941
Closed

ApiDataFactory with typescript factory file and ES6 export #3469

dwentland24 opened this issue Oct 22, 2022 · 0 comments · Fixed by #3941

Comments

@dwentland24
Copy link
Contributor

What are you trying to achieve?

I have a codeceptjs project where I use typescript. If I want to use the ApiDataFactory helper and create a factory file like

export default new Factory().attr('test', 'test')

I would expect that the ApiDataFactory helper is working. But as this ES6 Module export results in an object of {default: factoryObject } and the helper expects a direct factory object from importing the factory file, it cannot handle the ES6 Module exports. Returns an error:

Couldn't load factory file from /Users/dwentland/projects/dd-e2e-test-automation/dd-e2e-tests-ts/factories/user.ts, check that

  "factories": {
    "account": {
      "factory": "./path/to/factory"

points to valid factory file.
Factory file should export an object with build method.

Current file error: Assignment to constant variable.

I am not that deep into typescript right now, but is this behavior intended? Or do I miss any configuration to get the ES6 export to run with the helper? Or do I have to use the commonjs exports in my typescript files?

Actually it would be possible to check in the ApiDataFactory.js if the builder variable has a default property make it handle the commonjs and es6 module exports.

What do you get instead?

I would expect the helper to create the data.

Details

  • CodeceptJS version: 3.3.5
  • NodeJS Version: 18.11.0
  • Operating System: mac
  • Configuration file:
factories: {
        account: {
          fetchId: (data: any) => data.userId,
          factory: "./factories/user.ts",
          create: (data: any) => ({
            method: "post",
            url: "/rest/api/user",
            data: data,
          }),
          delete: (id: any) => ({
            method: "delete",
            url: `users/${id}`,
          }),
        },
      },
    },
@dwentland24 dwentland24 changed the title ApiDataFactory with typescript factory file ApiDataFactory with typescript factory file and ES6 export Oct 22, 2022
@kobenguyent kobenguyent linked a pull request Oct 20, 2023 that will close this issue
5 tasks
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.

1 participant