Fix specs that import a missing default export

What does this MR do and why?

Fixes four specs that import a default from a module that has no default export. In each case the binding was undefined, so the test asserted less than it appeared to:

  • diff_line_note_form_spec.js emitted undefined as the note payload. It now imports the named note mock.
  • promotion_requests/graphql/utils_spec.js assigned the mock client onto the default import of a mocked module. It now injects the client through a getter in the jest.mock factory.
  • international_phone_input_spec.js passed { countriesResolver: undefined } as resolvers. The spec writes the countries to the cache directly, so it now passes no resolvers.
  • list_selector/index_spec.js asserted on a property of the default import of a mocked module. It now asserts on the named getProjects mock.

The import-x/default ESLint rule found them. The rule is enabled upstream, in @gitlab/eslint-plugin, by gitlab-org/frontend/eslint-plugin!195 (merged). This MR does not enable it here.

The rule reads the export map that import-x/named already builds for every import, so it adds about 3.7 s to a full-repo run of about 5 min. The bundlers fail the build on the same mistake, but only for modules they reach. Specs, helpers, and scripts are only linted, and that is where the rule found its violations.

The same run also reports six default imports of worker modules. These are not bugs. Worker files have no exports, and the bundler supplies the default export through the ?worker loader, and Jest through web_worker_transformer.js. The MR that bumps the plugin must add _worker\.js$ to import-x/ignore in eslint.config.mjs.

import-x/namespace was measured in the same run and stays off. It cost 48 s per full run, more than import-x/named itself. The nine real findings it produced are fixed separately in !257794 (merged).

How to set up and validate locally

Run the linter with the rule forced on:

yarn lint:eslint:all --no-cache --rule 'import-x/default: error'
yarn jest ee/spec/frontend/diffs/components/diff_line_note_form_spec.js \
  ee/spec/frontend/members/promotion_requests/graphql/utils_spec.js \
  ee/spec/frontend/users/identity_verification/components/international_phone_input_spec.js \
  spec/frontend/vue_shared/components/list_selector/index_spec.js

The lint run reports import-x/default only for the six worker imports. The four specs pass.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

References

Edited by Miguel Rincon

Merge request reports

Loading
Loading