Skip to content

Commit

Permalink
fix: generated loader template (#1720)
Browse files Browse the repository at this point in the history
* fix: generated loader template

* fix: generators test

* refactor: Update test/loader/loader.test.js

Co-authored-by: James George <jamesgeorge998001@gmail.com>

Co-authored-by: Anshuman Verma <anshu.av97@gmail.com>
Co-authored-by: James George <jamesgeorge998001@gmail.com>
  • Loading branch information
3 people authored Aug 2, 2020
1 parent 2f05940 commit a380a78
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/generate-loader/templates/src/_index.js.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* https://webpack.js.org/contribute/writing-a-loader
*/

export default function loader(source) {
module.exports = function loader(source) {
const { loaders, resource, request, version, webpack } = this;

console.log('<%= name %>');
const newSource = `
/**
* <%= name %>
Expand Down
2 changes: 1 addition & 1 deletion packages/generators/__tests__/loader-generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('loader generator', () => {
// Check the contents of the webpack config and loader file
assert.fileContent([
[join(loaderDir, 'examples/simple/webpack.config.js'), /resolveLoader: {/],
[join(loaderDir, 'src/index.js'), /export default function loader\(source\) {/],
[join(loaderDir, 'src/index.js'), /module.exports = function loader\(source\) {/],
[join(loaderDir, 'package.json'), new RegExp(loaderName)],
]);

Expand Down
7 changes: 6 additions & 1 deletion test/loader/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('loader command', () => {
});

it('should scaffold loader template with a given name', async () => {
const { stdout } = await runPromptWithAnswers(__dirname, ['loader'], [`${loaderName}${ENTER}`]);
let { stdout } = await runPromptWithAnswers(__dirname, ['loader'], [`${loaderName}${ENTER}`]);

expect(stdout).toContain(firstPrompt);

Expand All @@ -46,5 +46,10 @@ describe('loader command', () => {
files.forEach((file) => {
expect(existsSync(join(__dirname, `${loaderName}/${file}`))).toBeTruthy();
});

//check if the the generated plugin works successfully
const path = resolve(__dirname, './test-loader/examples/simple/');
({ stdout } = run(path, [], false));
expect(stdout).toContain('test-loader');
});
});

0 comments on commit a380a78

Please sign in to comment.