-
-
Notifications
You must be signed in to change notification settings - Fork 617
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
languageSupport tests #1447
Merged
+113
−1
Merged
languageSupport tests #1447
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5c5f8f4
tests(generators): add language support tests
knagaitsev 15b01b5
tests(generators): add lang support tests for babel and ts
knagaitsev 9e2a3c5
tests(generators): check that include paths are correct
knagaitsev 56c4b24
chore(generators): fix ts type of function
knagaitsev 86e8472
tests(generators): switched lang support to use custom gen
knagaitsev 393f166
Merge branch 'next' into tests/lang-support
evilebottnawi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
86 changes: 86 additions & 0 deletions
86
packages/generators/__tests__/utils/languageSupport.test.ts
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import language, { LangType, getBabelLoader, getTypescriptLoader } from '../../lib/utils/languageSupport'; | ||
|
||
describe('languageSupport', () => { | ||
const getMockGenerator = (): any => { | ||
return { | ||
entryOption: "'./path/to/index.js'", | ||
dependencies: [], | ||
configuration: { | ||
config: { | ||
webpackOptions: { | ||
module: { | ||
rules: [], | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
}; | ||
|
||
it('getBabelLoader', () => { | ||
const rule = getBabelLoader(['test1', 'test2']); | ||
expect(rule.loader).toEqual("'babel-loader'"); | ||
expect(rule.include).toEqual(["path.resolve(__dirname, 'test1')", "path.resolve(__dirname, 'test2')"]); | ||
}); | ||
|
||
it('getTypescriptLoader', () => { | ||
const rule = getTypescriptLoader(['test1', 'test2']); | ||
expect(rule.loader).toEqual("'ts-loader'"); | ||
expect(rule.include).toEqual(["path.resolve(__dirname, 'test1')", "path.resolve(__dirname, 'test2')"]); | ||
}); | ||
|
||
it('works with ES6', () => { | ||
const gen = getMockGenerator(); | ||
language(gen, LangType.ES6); | ||
expect(gen.entryOption).toEqual("'./path/to/index.js'"); | ||
expect(gen.dependencies).toEqual(['babel-loader', '@babel/core', '@babel/preset-env']); | ||
|
||
const rules = gen.configuration.config.webpackOptions.module.rules; | ||
expect(rules.length).toEqual(1); | ||
expect(rules[0].include).toEqual(["path.resolve(__dirname, 'path/to')"]); | ||
}); | ||
|
||
it('works with TypeScript for single entry', () => { | ||
const gen = getMockGenerator(); | ||
language(gen, LangType.Typescript); | ||
// this helper preserves the original js entryOption but updates the | ||
// webpack config to use ts | ||
expect(gen.entryOption).toEqual("'./path/to/index.js'"); | ||
expect(gen.configuration.config.webpackOptions.entry).toEqual("'./path/to/index.ts'"); | ||
expect(gen.dependencies).toEqual(['typescript', 'ts-loader']); | ||
expect(gen.configuration.config.webpackOptions.module.rules.length).toEqual(1); | ||
|
||
const rules = gen.configuration.config.webpackOptions.module.rules; | ||
expect(rules.length).toEqual(1); | ||
expect(rules[0].include).toEqual(["path.resolve(__dirname, 'path/to')"]); | ||
}); | ||
|
||
it('works with TypeScript for multi entry', () => { | ||
const gen = getMockGenerator(); | ||
gen.entryOption = { | ||
test1: "'./path/to/test1.js'", | ||
test2: "'./path/to/test2.js'", | ||
test3: "'./different/path/to/test3.js'", | ||
}; | ||
language(gen, LangType.Typescript); | ||
// this helper preserves the original js entryOption but updates the | ||
// webpack config to use ts | ||
expect(gen.entryOption).toEqual({ | ||
test1: "'./path/to/test1.js'", | ||
test2: "'./path/to/test2.js'", | ||
test3: "'./different/path/to/test3.js'", | ||
}); | ||
expect(gen.configuration.config.webpackOptions.entry).toEqual({ | ||
test1: "'./path/to/test1.ts'", | ||
test2: "'./path/to/test2.ts'", | ||
test3: "'./different/path/to/test3.ts'", | ||
}); | ||
expect(gen.dependencies).toEqual(['typescript', 'ts-loader']); | ||
expect(gen.configuration.config.webpackOptions.module.rules.length).toEqual(1); | ||
|
||
const rules = gen.configuration.config.webpackOptions.module.rules; | ||
expect(rules.length).toEqual(1); | ||
// duplicate include paths are removed | ||
expect(rules[0].include).toEqual(["path.resolve(__dirname, 'path/to')", "path.resolve(__dirname, 'different/path/to')"]); | ||
}); | ||
}); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/сс @Loonride can you fix a warning?