Skip to content

Commit

Permalink
refactor(Webpack): Remove FileSorter (#712)
Browse files Browse the repository at this point in the history
Remove `toposort` file sorter. It is no longer support for transpilers to decide on the order of files.
  • Loading branch information
Sander Koenders authored and nicojs committed Apr 20, 2018
1 parent 9ccfe93 commit 54cbe58
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 170 deletions.
3 changes: 1 addition & 2 deletions packages/stryker-webpack-transpiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
"enhanced-resolve": "^4.0.0-beta.4",
"lodash": "^4.17.4",
"log4js": "^1.1.0",
"memory-fs": "^0.4.1",
"toposort": "^1.0.6"
"memory-fs": "^0.4.1"
},
"initStrykerConfig": {
"webpack": {
Expand Down
69 changes: 0 additions & 69 deletions packages/stryker-webpack-transpiler/src/compiler/FileSorter.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Compiler, Configuration } from 'webpack';
import webpack from './Webpack';
import InputFileSystem from '../fs/InputFileSystem';
import OutputFileSystem from '../fs/OutputFileSystem';
import FileSorter from './FileSorter';

export default class WebpackCompiler {
private _compiler: Compiler;
Expand Down Expand Up @@ -36,9 +35,8 @@ export default class WebpackCompiler {
public emit(): Promise<File[]> {
return this.compile().then(stats => {
const outputFiles = this._outputFS.collectFiles();
const jsonStats = stats.toJson({ chunks: true });
this._outputFS.purge();
return FileSorter.sort(outputFiles, jsonStats.chunks);
return outputFiles;
});
}

Expand Down
18 changes: 0 additions & 18 deletions packages/stryker-webpack-transpiler/test/helpers/producers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Configuration, Stats } from 'webpack';
import { WebpackCompilerMock } from './mockInterfaces';
import * as sinon from 'sinon';
import { Chunk } from '../../src/compiler/FileSorter';
import { StrykerWebpackConfig } from '../../src/WebpackTranspiler';
import { File } from 'stryker-api/core';

Expand Down Expand Up @@ -33,23 +32,6 @@ function createFactory<T>(defaultFn: () => T): (overrides?: Partial<T>) => T {
return overrides => Object.assign(defaultFn(), overrides);
}

export function createStats(chunks: Chunk[]) {
return {
hasErrors: () => false,
toJson() {
return {
chunks
};
}
};
}

export const createChunk = createFactory<Chunk>(() => ({
files: [],
id: '1',
parents: []
}));

export const createStrykerWebpackConfig = createFactory<StrykerWebpackConfig>(() => ({
configFile: undefined,
silent: true,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
import { expect } from 'chai';
import { File } from 'stryker-api/core';
import { createFakeWebpackConfig, createTextFile, createWebpackMock, Mock, createMockInstance, createStats, createChunk } from '../../helpers/producers';
import { createFakeWebpackConfig, createTextFile, createWebpackMock, Mock, createMockInstance } from '../../helpers/producers';
import { WebpackCompilerMock } from '../../helpers/mockInterfaces';
import InputFileSystem from '../../../src/fs/InputFileSystem';
import OutputFileSystem from '../../../src/fs/OutputFileSystem';
import WebpackCompiler from '../../../src/compiler/WebpackCompiler';
import * as webpack from '../../../src/compiler/Webpack';
import { Configuration } from 'webpack';
import FileSorter, { Chunk } from '../../../src/compiler/FileSorter';

describe('WebpackCompiler', () => {
let sut: WebpackCompiler;
let inputFileSystemMock: Mock<InputFileSystem>;
let outputFileSystemMock: Mock<OutputFileSystem>;
let webpackCompilerMock: WebpackCompilerMock;
let sortStub: sinon.SinonStub;
let fakeWebpackConfig: Configuration;

beforeEach(() => {
inputFileSystemMock = createMockInstance(InputFileSystem);
outputFileSystemMock = createMockInstance(OutputFileSystem);
webpackCompilerMock = createWebpackMock();
fakeWebpackConfig = createFakeWebpackConfig();
sortStub = sandbox.stub(FileSorter, 'sort');
sandbox.stub(webpack, 'default').returns(webpackCompilerMock);
});

Expand All @@ -44,12 +41,10 @@ describe('WebpackCompiler', () => {

describe('emit', () => {
let webpackRunStub: sinon.SinonStub;
let chunks: Chunk[];

beforeEach(() => {
chunks = [createChunk(), createChunk()];
sut = new WebpackCompiler(fakeWebpackConfig, inputFileSystemMock as any, outputFileSystemMock as any);
webpackRunStub = sandbox.stub(webpackCompilerMock, 'run').callsArgWith(0, null, createStats(chunks));
webpackRunStub = sandbox.stub(webpackCompilerMock, 'run').callsArgWith(0, null, { hasErrors: () => false });
});

it('should call the run function on the webpack compiler', async () => {
Expand All @@ -61,23 +56,12 @@ describe('WebpackCompiler', () => {
it('should collect files from the outputFS', async () => {
const expectedFiles = [{ name: 'foobar' }];
outputFileSystemMock.collectFiles.returns(expectedFiles);
sortStub.returns(expectedFiles);
const actualResult = await sut.emit();

expect(actualResult).eq(expectedFiles);
expect(outputFileSystemMock.collectFiles).calledWith();
});

it('should sort the files based on given chunks', async () => {
const expectedFiles = [{ name: 'foobar' }];
const expectedResult = ['1', '2', '3'];
outputFileSystemMock.collectFiles.returns(expectedFiles);
sortStub.returns(expectedResult);
const actualResult = await sut.emit();
expect(actualResult).deep.eq(expectedResult);
expect(sortStub).calledWith(expectedFiles, chunks);
});

it('should return an error when the webpack compiler fails to compile', async () => {
const fakeError: string = 'fakeError';
webpackRunStub.callsArgWith(0, new Error(fakeError));
Expand Down

0 comments on commit 54cbe58

Please sign in to comment.