diff --git a/test/fixtures/sass-data-prepend/index.js b/test/fixtures/sass-data-prepend/index.js index 423b033c..72dcf9c2 100644 --- a/test/fixtures/sass-data-prepend/index.js +++ b/test/fixtures/sass-data-prepend/index.js @@ -1 +1 @@ -import './style.scss'; +import './style.scss' diff --git a/test/index.test.js b/test/index.test.js index 2f5cb76d..b6d3ea2e 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -56,35 +56,36 @@ function snapshot({ options = {} }) { test(title, async () => { - let res + let result try { - res = await write({ + result = await write({ input, outDir, options }) - } catch (err) { - const frame = err.codeFrame || err.snippet + } catch (error) { + const frame = error.codeFrame || error.snippet if (frame) { - throw new Error(frame + err.message) + throw new Error(frame + error.message) } - throw err + + throw error } - expect(await res.jsCode()).toMatchSnapshot('js code') + expect(await result.jsCode()).toMatchSnapshot('js code') if (options.extract) { - expect(await res.hasCssFile()).toBe(true) - expect(await res.cssCode()).toMatchSnapshot('css code') + expect(await result.hasCssFile()).toBe(true) + expect(await result.cssCode()).toMatchSnapshot('css code') } const sourceMap = options && options.sourceMap if (sourceMap === 'inline') { - expect(await res.hasCssMapFile()).toBe(false) + expect(await result.hasCssMapFile()).toBe(false) } else if (sourceMap === true) { - expect(await res.hasCssMapFile()).toBe(Boolean(options.extract)) + expect(await result.hasCssMapFile()).toBe(Boolean(options.extract)) if (options.extract) { - expect(await res.cssMap()).toMatchSnapshot('css map') + expect(await result.cssMap()).toMatchSnapshot('css map') } } }) @@ -349,7 +350,7 @@ snapshotMany('sass', [ ]) test('onExtract', async () => { - const res = await write({ + const result = await write({ input: 'simple/index.js', outDir: 'onExtract', options: { @@ -359,8 +360,8 @@ test('onExtract', async () => { } } }) - expect(await res.jsCode()).toMatchSnapshot() - expect(await res.hasCssFile()).toBe(false) + expect(await result.jsCode()).toMatchSnapshot() + expect(await result.hasCssFile()).toBe(false) }) test('augmentChunkHash', async () => { @@ -381,6 +382,7 @@ test('augmentChunkHash', async () => { }) outputFiles.push(output[0]) } + const [fooOne, fooTwo, barOne] = outputFiles const fooHash = fooOne.fileName.split('.')[1] diff --git a/types/index.d.ts b/types/index.d.ts index a9041139..17d4d30c 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,44 +1,49 @@ import { Plugin } from 'rollup' import { CreateFilter } from 'rollup-pluginutils' -type FunctionType = (...args: T[]) => U; +type FunctionType = (...args: readonly T[]) => U; -type onExtract = (asset: { - code: any - map: any - codeFileName: string - mapFileName: string -}) => boolean +type onExtract = (asset: Readonly<{ + code: any; + map: any; + codeFileName: string; + mapFileName: string; +}>) => boolean; export type PostCSSPluginConf = { - inject?: boolean | { [key: string]: any } | ((cssVariableName: string, id: string) => string) - extract?: boolean | string - onExtract?: onExtract - modules?: boolean | { [key: string]: any } - extensions?: string[] - plugins?: any[] - autoModules?: boolean - namedExports?: boolean | ((id: string) => boolean) - minimize?: boolean | any - parser?: string | FunctionType - stringifier?: string | FunctionType - syntax?: string | FunctionType - exec?: boolean - config?: boolean | { - path: string - ctx: any - }; - to?: string - name?: any[] | any[][] - loaders?: any[] - onImport?: (id: string) => void - use?: string[] | { [key in 'sass' | 'stylus' | 'less']: any } - /** + inject?: + | boolean + | { [key: string]: any } + | ((cssVariableName: string, id: string) => string); + extract?: boolean | string; + onExtract?: onExtract; + modules?: boolean | { [key: string]: any }; + extensions?: string[]; + plugins?: any[]; + autoModules?: boolean; + namedExports?: boolean | ((id: string) => boolean); + minimize?: boolean | any; + parser?: string | FunctionType; + stringifier?: string | FunctionType; + syntax?: string | FunctionType; + exec?: boolean; + config?: + | boolean + | { + path: string; + ctx: any; + }; + to?: string; + name?: any[] | any[][]; + loaders?: any[]; + onImport?: (id: string) => void; + use?: string[] | { [key in 'sass' | 'stylus' | 'less']: any }; + /** * @default: false **/ - sourceMap?: boolean | 'inline' - include?: Parameters[0] - exclude?: Parameters[1] -} + sourceMap?: boolean | 'inline'; + include?: Parameters[0]; + exclude?: Parameters[1]; +}; -export default function (options: PostCSSPluginConf): Plugin +export default function (options: Readonly): Plugin