Skip to content

Commit

Permalink
fix: use absolute path to @lwc/jest-shared (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlawson authored Jun 30, 2023
1 parent 9a2c0c6 commit 81e6178
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/@lwc/jest-transformer/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ module.exports = {
// the transformer does not run in the same Node process as the serializer.
const magicString = new MagicString(result.code);

magicString.append(`\nconst { addKnownScopeToken } = require('@lwc/jest-shared');`);
// lwc-test may live in a different directory from the component module code, so
// we need to provide an absolute path
const jestSharedPath = require.resolve('@lwc/jest-shared');

magicString.append(`\nconst { addKnownScopeToken } = require(${JSON.stringify(jestSharedPath)});`);

for (const scopeToken of cssScopeTokens) {
magicString.append(`\naddKnownScopeToken(${JSON.stringify(scopeToken)});`)
Expand Down

0 comments on commit 81e6178

Please sign in to comment.