Skip to content

Commit

Permalink
Merge pull request #19 from 3c1u/fix/jest-28-process
Browse files Browse the repository at this point in the history
Return TransformedSource in process()
  • Loading branch information
dferber90 authored May 1, 2022
2 parents fd7c965 + 7fade65 commit 10c4e67
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ module.exports = {
(typeof transformConfig.config.modules === "function" &&
transformConfig.config.modules(filename)));
if (!useModules) {
return stripIndent`
const styleInject = require('style-inject');
return {
code: stripIndent`
const styleInject = require('style-inject');
styleInject(${JSON.stringify(src)});
module.exports = {};
`;
styleInject(${JSON.stringify(src)});
module.exports = {};
`,
};
}

// The "process" function of this Jest transform must be sync,
Expand Down Expand Up @@ -101,18 +103,22 @@ module.exports = {
// we forward the logs and return no mappings
console.error(result.stderr.toString());
console.log(result.stdout.toString());
return stripIndent`
console.error("transform-css: Failed to load '${filename}'");
module.exports = {};
`;
return {
code: stripIndent`
console.error("transform-css: Failed to load '${filename}'");
module.exports = {};
`,
};
}

// Finally, inject the styles to the document
return stripIndent`
const styleInject = require('style-inject');
return {
code: stripIndent`
const styleInject = require('style-inject');
styleInject(${JSON.stringify(css)});
module.exports = ${JSON.stringify(tokens)};
`;
styleInject(${JSON.stringify(css)});
module.exports = ${JSON.stringify(tokens)};
`,
};
},
};

0 comments on commit 10c4e67

Please sign in to comment.