-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
299 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<style lang="scss"> | ||
button { | ||
color: rgb(blue, 0.7); | ||
font-size: 16px; | ||
} | ||
</style> | ||
|
||
<button>I’m a button!</button> |
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,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`@snowpack/plugin-svelte unmocked generates code 1`] = `Promise {}`; |
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,69 @@ | ||
const mockCompiler = jest.fn().mockImplementation(() => ({js: ''})); | ||
const mockPreprocessor = jest.fn(); | ||
|
||
const path = require('path'); | ||
|
||
const mockConfig = {buildOptions: {sourceMaps: false}, installOptions: {rollup: {plugins: []}}}; | ||
const mockComponent = path.join(__dirname, 'Button.svelte'); | ||
|
||
describe('@snowpack/plugin-svelte', () => { | ||
describe('mocked ', () => { | ||
let plugin; | ||
|
||
beforeAll(() => { | ||
jest.mock('svelte/compiler', () => ({compile: mockCompiler, preprocess: mockPreprocessor})); // important: mock before import | ||
plugin = require('../plugin'); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.unmock('svelte/compiler'); | ||
}); | ||
|
||
afterEach(() => { | ||
mockCompiler.mockClear(); | ||
mockPreprocessor.mockClear(); | ||
}); | ||
|
||
it('passes options to compiler', () => { | ||
const options = { | ||
generate: 'ssr', | ||
isDev: false, | ||
}; | ||
const sveltePlugin = plugin(mockConfig, options); | ||
sveltePlugin.load({filePath: mockComponent}); | ||
const passedOptions = mockCompiler.mock.calls[0][1]; | ||
|
||
// this tests that all options passed above made it to the compiler | ||
// objectContaining() allows additional options to be passed, but we only care that our options have been preserved | ||
expect(passedOptions).toEqual(expect.objectContaining(options)); | ||
}); | ||
|
||
it('handles preprocessing', () => { | ||
// test-only config option | ||
const options = {__config: path.join(__dirname, 'svelte.config.js')}; | ||
|
||
const sveltePlugin = plugin(mockConfig, options); | ||
|
||
sveltePlugin.load({filePath: mockComponent}); | ||
jest.mock('svelte/compiler', () => ({compile: jest.fn(), preprocess: mockPreprocessor})); | ||
|
||
// as long as this function has been called, we can assume success | ||
expect(mockPreprocessor).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('unmocked', () => { | ||
let plugin; | ||
|
||
beforeAll(() => { | ||
plugin = require('../plugin'); | ||
}); | ||
|
||
it('generates code', () => { | ||
const options = {}; | ||
const sveltePlugin = plugin(mockConfig, options); | ||
const result = sveltePlugin.load({filePath: mockComponent}); | ||
expect(result).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
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,7 @@ | ||
const {sass} = require('svelte-preprocess-sass'); | ||
|
||
module.exports = { | ||
preprocess: { | ||
style: sass({}, {name: 'css'}), | ||
}, | ||
}; |
Oops, something went wrong.