-
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow to use
String
value for the `implementation option
- Loading branch information
1 parent
6658bbf
commit b118719
Showing
8 changed files
with
255 additions
and
11 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`implementation option should throw error when unresolved package: errors 1`] = ` | ||
Array [ | ||
"ModuleError: Module Error (from \`replaced original path\`): | ||
(Emitted value instead of an instance of Error) Error: Cannot find module 'unresolved' from 'src/utils.js'", | ||
] | ||
`; | ||
|
||
exports[`implementation option should throw error when unresolved package: warnings 1`] = `Array []`; | ||
|
||
exports[`implementation option should work when implementation option is string: css 1`] = ` | ||
"body { | ||
font: 12px Helvetica, Arial, sans-serif; | ||
} | ||
a.button { | ||
-webkit-border-radius: 5px; | ||
-moz-border-radius: 5px; | ||
border-radius: 5px; | ||
} | ||
" | ||
`; | ||
|
||
exports[`implementation option should work when implementation option is string: errors 1`] = `Array []`; | ||
|
||
exports[`implementation option should work when implementation option is string: warnings 1`] = `Array []`; | ||
|
||
exports[`implementation option should work: css 1`] = ` | ||
"body { | ||
font: 12px Helvetica, Arial, sans-serif; | ||
} | ||
a.button { | ||
-webkit-border-radius: 5px; | ||
-moz-border-radius: 5px; | ||
border-radius: 5px; | ||
} | ||
" | ||
`; | ||
|
||
exports[`implementation option should work: errors 1`] = `Array []`; | ||
|
||
exports[`implementation option should work: warnings 1`] = `Array []`; |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* @jest-environment node | ||
*/ | ||
|
||
import { | ||
compile, | ||
getCodeFromBundle, | ||
getCodeFromStylus, | ||
getCompiler, | ||
getErrors, | ||
getWarnings, | ||
} from "./helpers"; | ||
|
||
jest.setTimeout(30000); | ||
|
||
describe("implementation option", () => { | ||
it("should work", async () => { | ||
const testId = "./basic.styl"; | ||
const compiler = getCompiler(testId, { | ||
// eslint-disable-next-line global-require | ||
implementation: require("stylus"), | ||
}); | ||
const stats = await compile(compiler); | ||
const codeFromBundle = getCodeFromBundle(stats, compiler); | ||
const codeFromStylus = await getCodeFromStylus(testId); | ||
|
||
expect(codeFromBundle.css).toBe(codeFromStylus.css); | ||
expect(codeFromBundle.css).toMatchSnapshot("css"); | ||
expect(getWarnings(stats)).toMatchSnapshot("warnings"); | ||
expect(getErrors(stats)).toMatchSnapshot("errors"); | ||
}); | ||
|
||
it("should work when implementation option is string", async () => { | ||
const testId = "./basic.styl"; | ||
const compiler = getCompiler(testId, { | ||
implementation: require.resolve("stylus"), | ||
}); | ||
const stats = await compile(compiler); | ||
const codeFromBundle = getCodeFromBundle(stats, compiler); | ||
const codeFromStylus = await getCodeFromStylus(testId); | ||
|
||
expect(codeFromBundle.css).toBe(codeFromStylus.css); | ||
expect(codeFromBundle.css).toMatchSnapshot("css"); | ||
expect(getWarnings(stats)).toMatchSnapshot("warnings"); | ||
expect(getErrors(stats)).toMatchSnapshot("errors"); | ||
}); | ||
|
||
it("should throw error when unresolved package", async () => { | ||
const testId = "./basic.styl"; | ||
const compiler = getCompiler(testId, { | ||
implementation: "unresolved", | ||
}); | ||
const stats = await compile(compiler); | ||
|
||
expect(getWarnings(stats)).toMatchSnapshot("warnings"); | ||
expect(getErrors(stats)).toMatchSnapshot("errors"); | ||
}); | ||
}); |
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