-
-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests(loader-generator): add tests for loader generator (#1234)
* tests(loader-generator): add tests for loader generator add tests for loader generator * tests(loader): fix import order fix import order
- Loading branch information
Showing
3 changed files
with
53 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |