Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Commit

Permalink
test: standardize test configuration (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-ciniawsky authored and joshwiens committed Nov 22, 2017
1 parent f321874 commit 52c882e
Show file tree
Hide file tree
Showing 26 changed files with 3,606 additions and 1,202 deletions.
4,155 changes: 3,170 additions & 985 deletions package-lock.json

Large diffs are not rendered by default.

46 changes: 20 additions & 26 deletions package.json
Expand Up @@ -11,30 +11,29 @@
"files": [
"dist"
],
"directories": {
"test": "test"
},
"dependencies": {
"loader-utils": "^1.0.2",
"schema-utils": "^0.3.0"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-jest": "^20.0.3",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-polyfill": "^6.23.0",
"babel-preset-env": "^1.5.1",
"babel-cli": "^6.0.0",
"babel-jest": "^21.0.0",
"babel-plugin-transform-object-rest-spread": "^6.0.0",
"babel-polyfill": "^6.0.0",
"babel-preset-env": "^1.0.0",
"cross-env": "^5.0.0",
"del": "^3.0.0",
"del-cli": "^1.0.0",
"eslint": "^3.19.0",
"eslint-config-webpack": "^1.2.3",
"eslint-plugin-import": "^2.3.0",
"jest": "^20.0.4",
"lint-staged": "^3.6.0",
"nsp": "^2.6.3",
"pre-commit": "^1.2.2",
"eslint": "^4.0.0",
"eslint-config-webpack": "^1.0.0",
"eslint-plugin-import": "^2.0.0",
"jest": "^21.0.0",
"lint-staged": "^5.0.0",
"memory-fs": "^0.4.0",
"nsp": "^2.0.0",
"pre-commit": "^1.0.0",
"standard-version": "^4.0.0",
"webpack": "^3.6.0",
"webpack": "^3.0.0",
"webpack-defaults": "^1.6.0"
},
"peerDependencies": {
Expand All @@ -54,19 +53,14 @@
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --collectCoverageFrom='src/**/*.js' --coverage",
"travis:coverage": "npm run test:coverage -- --runInBand",
"travis:test": "npm run test -- --runInBand",
"travis:lint": "npm run lint && npm run security",
"travis:test": "npm run test -- --runInBand",
"travis:coverage": "npm run test:coverage -- --runInBand",
"webpack-defaults": "webpack-defaults"
},
"repository": {
"type": "git",
"url": "https://github.com/webpack/file-loader.git"
},
"bugs": {
"url": "https://github.com/webpack/file-loader/issues"
},
"homepage": "https://github.com/webpack/file-loader",
"repository": "https://github.com/webpack/file-loader.git",
"bugs": "https://github.com/webpack/file-loader/issues",
"homepage": "https://webpack.js.org/loaders/file-loader",
"pre-commit": "lint-staged",
"lint-staged": {
"*.js": [
Expand Down
14 changes: 7 additions & 7 deletions test/Errors.test.js
@@ -1,18 +1,18 @@
import loader from '../src';

describe('Errors', () => {
test('Validation Error', () => {
const err = () => loader.call({
query: { useRelativePath: 1 },
emitFile: true,
});
test('Loader Error', () => {
const err = () => loader.call({ emitFile: false });

expect(err).toThrow();
expect(err).toThrowErrorMatchingSnapshot();
});

test('Loader Error', () => {
const err = () => loader.call({ emitFile: false });
test('Validation Error', () => {
const err = () => loader.call({
query: { useRelativePath: 1 },
emitFile: true,
});

expect(err).toThrow();
expect(err).toThrowErrorMatchingSnapshot();
Expand Down
3 changes: 3 additions & 0 deletions test/__snapshots__/loader.test.js.snap
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Loader Defaults 1`] = `"module.exports = __webpack_public_path__ + \\"9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";"`;
10 changes: 5 additions & 5 deletions test/cjs.test.js
@@ -1,12 +1,12 @@
import fileLoader from '../src';
import cjsFileLoader from '../src/cjs';
import loader from '../src';
import CJSLoader from '../src/cjs';

describe('cjs', () => {
describe('CJS', () => {
it('should export loader', () => {
expect(cjsFileLoader).toEqual(fileLoader);
expect(CJSLoader).toEqual(loader);
});

it('should export `raw` flag', () => {
expect(cjsFileLoader.raw).toEqual(true);
expect(CJSLoader.raw).toEqual(true);
});
});
30 changes: 0 additions & 30 deletions test/emitFile.test.js

This file was deleted.

4 changes: 4 additions & 0 deletions test/fixtures/emitFile/fixture.js
@@ -0,0 +1,4 @@
/* eslint-disable */
import svg from '../file.svg';

export default svg
Binary file added test/fixtures/file.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/fixtures/file.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/fixtures/file.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions test/fixtures/file.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions test/fixtures/fixture.js
@@ -0,0 +1,4 @@
/* eslint-disable */
import png from './file.png';

export default png;
68 changes: 68 additions & 0 deletions test/helpers/compiler.js
@@ -0,0 +1,68 @@
/* eslint-disable
import/order,
multiline-ternary,
no-param-reassign,
*/
import del from 'del';
import path from 'path';
import webpack from 'webpack';
import MemoryFS from 'memory-fs';

const module = (config) => {
return {
rules: config.rules || config.loader
? [
{
test: config.loader.test || /\.txt$/,
use: {
loader: path.resolve(__dirname, '../../src'),
options: config.loader.options || {},
},
},
]
: [],
};
};

const plugins = config => ([
new webpack.optimize.CommonsChunkPlugin({
name: ['runtime'],
minChunks: Infinity,
}),
].concat(config.plugins || []));

const output = (config) => {
return {
path: path.resolve(
__dirname,
`../outputs/${config.output ? config.output : ''}`,
),
filename: '[name].bundle.js',
};
};

export default function (fixture, config, options) {
// webpack Config
config = {
devtool: config.devtool || 'sourcemap',
context: path.resolve(__dirname, '..', 'fixtures'),
entry: `./${fixture}`,
output: output(config),
module: module(config),
plugins: plugins(config),
};
// Compiler Options
options = Object.assign({ output: false }, options);

if (options.output) del.sync(config.output.path);

const compiler = webpack(config);

if (!options.output) compiler.outputFileSystem = new MemoryFS();

return new Promise((resolve, reject) => compiler.run((err, stats) => {
if (err) reject(err);

resolve(stats);
}));
}

0 comments on commit 52c882e

Please sign in to comment.