Skip to content

Cannot find module of frontend addon package in test #165

Open
@wesleybl

Description

@wesleybl

If my package has an import of the type:

import { test } from '@org/my-addon/helpers/Test'

The test does not find the module.

To reproduce:

  • Create a frontend addon.
  • Answers to the questions to define the name of the addon:
  [1/8] Add-on Title (Volto Add-on):   
  [2/8] Add-on (Short name of the addon) (volto-add-on): my-addon 
  [3/8] A short description of your addon (A new add-on for Volto): 
  [4/8] Author (Plone Community): 
  [5/8] Author E-mail ([email protected]): 
  [6/8] GitHub Username or Organization (collective): 
  [7/8] Package name on NPM (my-addon): @org/my-addon
  [8/8] Volto version (18.9.0): 
  • Enter the folder and run:

git init
make install

  • Create the following files:

my-addon/packages/my-addon/src/helpers/Test.js

export function test() {
  return 'ok';
}

my-addon/packages/my-addon/src/Test.js

import { test } from '@org/my-addon/helpers/Test'

export function ok() {
  return test();
}

my-addon/packages/my-addon/src/Test.test.js

import { ok } from './Test';

it('test', () => {
  ok();
});
  • Run make test.

I get the error:

 FAIL  ../../../packages/my-addon/src/Test.test.js
  ● Test suite failed to run

    Cannot find module '@org/my-addon/helpers/Test' from '../../../packages/my-addon/src/Test.js'

    Require stack:
      /home/user/my-addon/packages/my-addon/src/Test.js
      /home/user/my-addon/packages/my-addon/src/Test.test.js

    > 1 | import { test } from '@org/my-addon/helpers/Test'
        | ^
      2 |
      3 | export function ok() {
      4 |   return test();

      at Resolver.resolveModule (../../../node_modules/.pnpm/[email protected]/node_modules/jest-resolve/build/index.js:306:11)
      at Object.<anonymous> (../../../packages/my-addon/src/Test.js:1:1)
      at Object.<anonymous> (../../../packages/my-addon/src/Test.test.js:1:1)

It seems that the moduleNameMapper used in this is the one from Volto, and there is no our package there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions