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

tests(loader-generator): add tests for loader generator #1234

Merged
merged 2 commits into from
Feb 17, 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
8 changes: 7 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,12 @@
"lint-staged": "^9.4.2",
"nyc": "^14.1.1",
"prettier": "1.18.2",
"readable-stream": "^3.5.0",
"ts-jest": "^24.1.0",
"typedoc": "^0.15.0",
"typescript": "^3.7.2",
"webpack": "^5.0.0-beta.12",
"yeoman-test": "^2.1.0",
"readable-stream": "^3.5.0"
"yeoman-assert": "^3.1.1",
"yeoman-test": "^2.1.0"
}
}
55 changes: 43 additions & 12 deletions packages/generators/__tests__/loader-generator.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,44 @@
import { makeLoaderName } from "../loader-generator";

describe("makeLoaderName", () => {
it("should kebab-case loader name and append '-loader'", () => {
const loaderName = makeLoaderName("This is a test");
expect(loaderName).toEqual("this-is-a-test-loader");
});

it("should not modify a properly formatted loader name", () => {
const loaderName = makeLoaderName("properly-named-loader");
expect(loaderName).toEqual("properly-named-loader");
});
import { join } from 'path';
import { run } from 'yeoman-test';
const assert = require('yeoman-assert');
import { makeLoaderName } from '../loader-generator';

describe('loader generator', () => {
it('generates a default loader', async () => {
const outputDir = await run(join(__dirname, '../loader-generator'));
const loaderDir = `${outputDir}/my-loader`;
const srcFiles = ['cjs.js', 'index.js'];
const testFiles = ['functional.test.js', 'test-utils.js', 'unit.test.js', 'fixtures/simple-file.js'];
const exampleFiles = ['webpack.config.js', 'src/index.js', 'src/lazy-module.js', 'src/static-esm-module.js'];

// Check that files in all folders are scaffolded. Checking them separately so we know which directory has the problem
// assert for src files
assert.file([...srcFiles.map(file => `${loaderDir}/src/${file}`)]);

// assert for test files
assert.file([...testFiles.map(file => `${loaderDir}/test/${file}`)]);

// assert for example files
assert.file([...exampleFiles.map(file => `${loaderDir}/examples/simple/${file}`)]);

// Check the contents of the webpack config and loader file
assert.fileContent([
[`${loaderDir}/examples/simple/webpack.config.js`, 'resolveLoader: {'],
[`${loaderDir}/src/index.js`, 'export default function loader(source) {'],
]);

// higher timeout so travis has enough time to execute
}, 10000);
});

describe('makeLoaderName', () => {
it("should kebab-case loader name and append '-loader'", () => {
const loaderName = makeLoaderName('This is a test');
expect(loaderName).toEqual('this-is-a-test-loader');
});

it('should not modify a properly formatted loader name', () => {
const loaderName = makeLoaderName('properly-named-loader');
expect(loaderName).toEqual('properly-named-loader');
});
});