Skip to content

Commit

Permalink
tests(loader-generator): add tests for loader generator
Browse files Browse the repository at this point in the history
add tests for loader generator
  • Loading branch information
anshumanv committed Feb 16, 2020
1 parent f29a170 commit a5af8ee
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 15 deletions.
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 { makeLoaderName } from '../loader-generator';
import { join } from 'path';
import { run } from 'yeoman-test';
const assert = require('yeoman-assert');

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

0 comments on commit a5af8ee

Please sign in to comment.