Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: generated loader template #1720

Merged
merged 6 commits into from
Aug 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should implement --babel option to this in future (put babel config and generate es module syntax)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will implement in future PR.

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');
});
});