Skip to content

Commit

Permalink
Add webpack-image-optimization test
Browse files Browse the repository at this point in the history
  • Loading branch information
sumanthratna committed Jan 9, 2022
1 parent a6c2f51 commit 27241a6
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/fixtures/webpack-image-optimization/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const testSetup = require('../__shared__/test-setup');

const fs = require('fs-extra');
const globby = require('globby');
const path = require('path');

test('optimizes in production', async () => {
const { fulfilled } = await testSetup.scripts.build();
expect(fulfilled).toBe(true);

const buildDir = path.join(testSetup.testDirectory, 'build');
const builtImageFile = path.join(
buildDir,
globby.sync('**/*.png', { cwd: buildDir }).pop()
);
const recievedBuf = fs.readFileSync(builtImageFile);

const expectedImageFile = path.join(
testSetup.templateDirectory,
'./src/images/webpack-optimized.png'
);
const expectedBuf = fs.readFileSync(expectedImageFile);

expect(recievedBuf).toStrictEqual(expectedBuf);
});
6 changes: 6 additions & 0 deletions test/fixtures/webpack-image-optimization/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"react": "latest",
"react-dom": "latest"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions test/fixtures/webpack-image-optimization/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#root {
width: 300px;
height: 300px;
background: url(./images/webpack-unoptimized.png) center/cover no-repeat;
}
5 changes: 5 additions & 0 deletions test/fixtures/webpack-image-optimization/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';

ReactDOM.render(<div />, document.getElementById('root'));

0 comments on commit 27241a6

Please sign in to comment.