Skip to content

Commit

Permalink
Added fixes for next set of tests. Some cleanup. API finetuning.
Browse files Browse the repository at this point in the history
  • Loading branch information
swernerx committed Jul 25, 2018
1 parent 29802e0 commit 92da7d6
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 197 deletions.
36 changes: 32 additions & 4 deletions __tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,41 @@ export default assets;
`;

exports[`Assets written to subfolder 1`] = `
"import font from './img/cNxsXFOx.woff';
import image from './img/fEGHuKIT.png';
import deep from './img/ceBqZEDY.gif';
import style from './img/gayDQjlm.css';
"import font from './static/cNxsXFOx.woff';
import image from './static/fEGHuKIT.png';
import deep from './static/ceBqZEDY.gif';
import style from './static/gayDQjlm.css';
var assets = \`\${font}|\${image}|\${deep}|\${style}\`;
export default assets;
"
`;

exports[`Mixed Asset Source Locations 1`] = `
"import font from './cNxsXFOx.woff';
import svg from './foixBwnR.svg';
import deep from './ceBqZEDY.gif';
import style from './gayDQjlm.css';
/* eslint-disable filenames/match-regex */
var assetsMixed = \`\${font}|\${svg}|\${deep}|\${style}\`;
export default assetsMixed;
"
`;

exports[`Outside Asset Source Location 1`] = `
"import font from './cNxsXFOx.woff';
import image from './fEGHuKIT.png';
import deep from './ceBqZEDY.gif';
import style from './gayDQjlm.css';
/* eslint-disable filenames/match-regex */
var assetsOutside = \`\${font}|\${image}|\${deep}|\${style}\`;
export default assetsOutside;
"
`;
149 changes: 73 additions & 76 deletions __tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import fs from "fs-extra"
import { rollup } from "rollup"
import denodeify from "denodeify"
import rimraf from "rimraf"
import { dirname } from "path"

import rebasePlugin from "../src"

Expand All @@ -13,8 +12,7 @@ const readFile = denodeify(fs.readFile)
const outputFolder = "./__tests__/output/"

function bundle(input, outputFile, pluginOptions = {}) {
const outputFolder = dirname(outputFile)
const plugin = rebasePlugin({ outputFolder, input, verbose: true, ...pluginOptions })
const plugin = rebasePlugin(pluginOptions)

return rollup({
input,
Expand Down Expand Up @@ -83,15 +81,14 @@ test("Assets", () => {
test("Assets written to subfolder", () => {
const outputFile = `${outputFolder}/assets-subfolder/index.js`

const imageFile = `${outputFolder}/assets-subfolder/img/fEGHuKIT.png`
const fontFile = `${outputFolder}/assets-subfolder/img/cNxsXFOx.woff`
const deepFile = `${outputFolder}/assets-subfolder/img/ceBqZEDY.gif`
const cssFile = `${outputFolder}/assets-subfolder/img/gayDQjlm.css`
const cssFont = `${outputFolder}/assets-subfolder/img/gadyfD.woff`
const imageFile = `${outputFolder}/assets-subfolder/static/fEGHuKIT.png`
const fontFile = `${outputFolder}/assets-subfolder/static/cNxsXFOx.woff`
const deepFile = `${outputFolder}/assets-subfolder/static/ceBqZEDY.gif`
const cssFile = `${outputFolder}/assets-subfolder/static/gayDQjlm.css`
const cssFont = `${outputFolder}/assets-subfolder/static/gadyfD.woff`

const options = {
outputFolder: `${outputFolder}assets-subfolder/img/`,
outputBase: dirname(outputFile)
folder: "static"
}

return bundle("./__tests__/fixtures/assets.js", outputFile, options)
Expand Down Expand Up @@ -120,77 +117,77 @@ test("Assets written to subfolder", () => {
)
})

// test("Outside Assets", () => {
// const outputFile = `${outputFolder}/outside/index.js`
test("Outside Asset Source Location", () => {
const outputFile = `${outputFolder}/outside/index.js`

// const imageFile = `${outputFolder}/outside/fEGHuKIT.png`
// const fontFile = `${outputFolder}/outside/cNxsXFOx.woff`
// const deepFile = `${outputFolder}/outside/ceBqZEDY.gif`
// const cssFile = `${outputFolder}/outside/gayDQjlm.css`
// const cssFont = `${outputFolder}/outside/gadyfD.woff`
const imageFile = `${outputFolder}/outside/fEGHuKIT.png`
const fontFile = `${outputFolder}/outside/cNxsXFOx.woff`
const deepFile = `${outputFolder}/outside/ceBqZEDY.gif`
const cssFile = `${outputFolder}/outside/gayDQjlm.css`
const cssFont = `${outputFolder}/outside/gadyfD.woff`

// return bundle("./__tests__/fixtures/deep/assets-outside.js", outputFile)
// .then(() =>
// Promise.all([
// expect(fileExists(outputFile)).resolves.toBeTruthy(),
// readFile(outputFile, "utf-8").then((content) => {
// expect(content).toMatchSnapshot()
// }),
// expect(fileExists(imageFile)).resolves.toBeTruthy(),
// expect(fileExists(fontFile)).resolves.toBeTruthy(),
// expect(fileExists(deepFile)).resolves.toBeTruthy(),
// expect(fileExists(cssFile)).resolves.toBeTruthy(),
// expect(fileExists(cssFont)).resolves.toBeTruthy()
// ])
// )
// .then(
// Promise.all([
// rimrafp(outputFile),
// rimrafp(imageFile),
// rimrafp(fontFile),
// rimrafp(deepFile),
// rimrafp(cssFile),
// rimrafp(cssFont)
// ])
// )
// })
return bundle("./__tests__/fixtures/deep/assets-outside.js", outputFile)
.then(() =>
Promise.all([
expect(fileExists(outputFile)).resolves.toBeTruthy(),
readFile(outputFile, "utf-8").then((content) => {
expect(content).toMatchSnapshot()
}),
expect(fileExists(imageFile)).resolves.toBeTruthy(),
expect(fileExists(fontFile)).resolves.toBeTruthy(),
expect(fileExists(deepFile)).resolves.toBeTruthy(),
expect(fileExists(cssFile)).resolves.toBeTruthy(),
expect(fileExists(cssFont)).resolves.toBeTruthy()
])
)
.then(
Promise.all([
rimrafp(outputFile),
rimrafp(imageFile),
rimrafp(fontFile),
rimrafp(deepFile),
rimrafp(cssFile),
rimrafp(cssFont)
])
)
})

// test("Mixed Assets", () => {
// const outputFile = `${outputFolder}/mixed/index.js`
test("Mixed Asset Source Locations", () => {
const outputFile = `${outputFolder}/mixed/index.js`

// const fontFile = `${outputFolder}/mixed/cNxsXFOx.woff`
// const svgFile = `${outputFolder}/mixed/dBNImC.svg`
// const deepFile = `${outputFolder}/mixed/ceBqZEDY.gif`
// const cssFile = `${outputFolder}/mixed/gayDQjlm.css`
// const cssFont = `${outputFolder}/mixed/gadyfD.woff`
const fontFile = `${outputFolder}/mixed/cNxsXFOx.woff`
const svgFile = `${outputFolder}/mixed/foixBwnR.svg`
const deepFile = `${outputFolder}/mixed/ceBqZEDY.gif`
const cssFile = `${outputFolder}/mixed/gayDQjlm.css`
const cssFont = `${outputFolder}/mixed/gadyfD.woff`

// return bundle("./__tests__/fixtures/deep/assets-mixed.js", outputFile)
// .then(() =>
// Promise.all([
// expect(fileExists(outputFile)).resolves.toBeTruthy(),
// readFile(outputFile, "utf-8").then((content) => {
// expect(content).toMatchSnapshot()
// }),
// expect(fileExists(fontFile)).resolves.toBeTruthy(),
// expect(fileExists(svgFile)).resolves.toBeTruthy(),
// expect(fileExists(deepFile)).resolves.toBeTruthy(),
// expect(fileExists(cssFile)).resolves.toBeTruthy(),
// expect(fileExists(cssFont)).resolves.toBeTruthy()
// ])
// )
// .then(
// Promise.all([
// rimrafp(outputFile),
// rimrafp(fontFile),
// rimrafp(svgFile),
// rimrafp(deepFile),
// rimrafp(cssFile),
// rimrafp(cssFont)
// ])
// )
// })
return bundle("./__tests__/fixtures/deep/assets-mixed.js", outputFile)
.then(() =>
Promise.all([
expect(fileExists(outputFile)).resolves.toBeTruthy(),
readFile(outputFile, "utf-8").then((content) => {
expect(content).toMatchSnapshot()
}),
expect(fileExists(fontFile)).resolves.toBeTruthy(),
expect(fileExists(svgFile)).resolves.toBeTruthy(),
expect(fileExists(deepFile)).resolves.toBeTruthy(),
expect(fileExists(cssFile)).resolves.toBeTruthy(),
expect(fileExists(cssFont)).resolves.toBeTruthy()
])
)
.then(
Promise.all([
rimrafp(outputFile),
rimrafp(fontFile),
rimrafp(svgFile),
rimrafp(deepFile),
rimrafp(cssFile),
rimrafp(cssFont)
])
)
})

// test("Assets with hash appeneded", () => {
// test("Keep Name", () => {
// const outputFile = `${outputFolder}/assets-hash-appened/index.js`

// const imageFile = `${outputFolder}/assets-hash-appened/image_fEGHuKIT.png`
Expand All @@ -200,7 +197,7 @@ test("Assets written to subfolder", () => {
// const cssFont = `${outputFolder}/assets-hash-appened/css-font_gadyfD.woff`

// return bundle("./__tests__/fixtures/assets.js", outputFile, {
// prependName: true
// keepName: true
// })
// .then(() =>
// Promise.all([
Expand Down
13 changes: 6 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const rebase = rebasePlugin({ outputFolder, input })

rollup({
input: input,
external: rebase.isExternal,
plugins: [
rebase
]
Expand All @@ -72,13 +71,13 @@ rollup({
```

### Options

* input (required): The location of your entry point for rollup
* outputFolder (required): The location that assets will be written to
* outputBase: The main rollup output folder. Defaults to outputFolder if not set.
* prependName: If true, generated filenames will be ORIGINALFILENAME_HASH instead of just HASH
* verbose: If true, increases log level
* include: Standard include option for rollup plugins. Supports a minimatch string.
* exlude: Standard exclude option for rollup plugins. Supports a minimatch string.
* folder: When set assets are placed inside a sub folder with that name.
* keepName: If `true`, generated filenames will be `${filename}_${hash}.${ext}` instead of just `${hash}.${ext}`
* verbose: If `true`, increases log level
* include: Standard include option for rollup plugins.
* exlude: Standard exclude option for rollup plugins.


## Copyright
Expand Down
Loading

0 comments on commit 92da7d6

Please sign in to comment.