This repository has been archived by the owner on May 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(uglify): verify source maps are generated correctly for all bundl…
…es, tests * refactor(optimization): don't delete file from disk since we now write to memory don't delete file from disk since we now write to memory * test(babili): fix babili tests fix babili tests * needs tests but working * tests
- Loading branch information
1 parent
869455e
commit fc44ca6
Showing
7 changed files
with
181 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,71 @@ | ||
import * as uglifyjs from './uglifyjs'; | ||
import * as configUtil from './util/config'; | ||
import * as workerClient from './worker-client'; | ||
|
||
describe('uglifyjs function', () => { | ||
beforeEach(() => { | ||
spyOn(configUtil, 'getUserConfigFile').and.returnValue('fileContents'); | ||
spyOn(workerClient, 'runWorker').and.returnValue(Promise.resolve()); | ||
}); | ||
import * as fs from 'fs'; | ||
import { join } from 'path'; | ||
|
||
it('should call workerClient function', () => { | ||
const context = {}; | ||
const configFile = 'configFileContents'; | ||
import * as uglifyLib from 'uglify-js'; | ||
|
||
return uglifyjs.uglifyjs(context, configFile).then(() => { | ||
expect(configUtil.getUserConfigFile).toHaveBeenCalledWith(context, uglifyjs.taskInfo, configFile); | ||
expect(workerClient.runWorker).toHaveBeenCalledWith('uglifyjs', 'uglifyjsWorker', context, 'fileContents'); | ||
}); | ||
}); | ||
import * as helpers from './util/helpers'; | ||
import * as uglifyTask from './uglifyjs'; | ||
|
||
it('should fail because it does not have a valid build context', () => { | ||
const context: null = null; | ||
const configFile = 'configFileContents'; | ||
|
||
expect(uglifyjs.uglifyjs(context, configFile)).toThrow(); | ||
}); | ||
describe('uglifyjs', () => { | ||
describe('uglifyjsWorkerImpl', () => { | ||
it('should call uglify for the appropriate files', () => { | ||
const buildDir = join('some', 'fake', 'dir', 'myApp', 'www', 'build'); | ||
const context = { | ||
buildDir: buildDir | ||
}; | ||
const fileNames = ['polyfills.js', 'sw-toolbox.js', '0.main.js', '0.main.js.map', '1.main.js', '1.main.js.map', 'main.js', 'main.js.map']; | ||
const mockMinfiedResponse = { | ||
code: 'code', | ||
map: 'map' | ||
}; | ||
const mockUglifyConfig = { | ||
mangle: true, | ||
compress: true | ||
}; | ||
|
||
it('should fail because it does not have a valid config file', () => { | ||
const context = {}; | ||
const configFile: null = null; | ||
spyOn(fs, 'readdirSync').and.returnValue(fileNames); | ||
const uglifySpy = spyOn(uglifyLib, 'minify').and.returnValue(mockMinfiedResponse); | ||
const writeFileSpy = spyOn(helpers, helpers.writeFileAsync.name).and.returnValue(Promise.resolve()); | ||
|
||
expect(uglifyjs.uglifyjs(context, configFile)).toThrow(); | ||
}); | ||
const promise = uglifyTask.uglifyjsWorkerImpl(context, mockUglifyConfig); | ||
|
||
return promise.then(() => { | ||
expect(uglifyLib.minify).toHaveBeenCalledTimes(3); | ||
expect(uglifySpy.calls.all()[0].args[0]).toEqual(join(buildDir, '0.main.js')); | ||
expect(uglifySpy.calls.all()[0].args[1].compress).toEqual(true); | ||
expect(uglifySpy.calls.all()[0].args[1].mangle).toEqual(true); | ||
expect(uglifySpy.calls.all()[0].args[1].inSourceMap).toEqual(join(buildDir, '0.main.js.map')); | ||
expect(uglifySpy.calls.all()[0].args[1].outSourceMap).toEqual(join(buildDir, '0.main.js.map')); | ||
|
||
expect(uglifySpy.calls.all()[1].args[0]).toEqual(join(buildDir, '1.main.js')); | ||
expect(uglifySpy.calls.all()[1].args[1].compress).toEqual(true); | ||
expect(uglifySpy.calls.all()[1].args[1].mangle).toEqual(true); | ||
expect(uglifySpy.calls.all()[1].args[1].inSourceMap).toEqual(join(buildDir, '1.main.js.map')); | ||
expect(uglifySpy.calls.all()[1].args[1].outSourceMap).toEqual(join(buildDir, '1.main.js.map')); | ||
|
||
expect(uglifySpy.calls.all()[2].args[0]).toEqual(join(buildDir, 'main.js')); | ||
expect(uglifySpy.calls.all()[2].args[1].compress).toEqual(true); | ||
expect(uglifySpy.calls.all()[2].args[1].mangle).toEqual(true); | ||
expect(uglifySpy.calls.all()[2].args[1].inSourceMap).toEqual(join(buildDir, 'main.js.map')); | ||
expect(uglifySpy.calls.all()[2].args[1].outSourceMap).toEqual(join(buildDir, 'main.js.map')); | ||
|
||
expect(writeFileSpy).toHaveBeenCalledTimes(6); | ||
expect(writeFileSpy.calls.all()[0].args[0]).toEqual(join(buildDir, '0.main.js')); | ||
expect(writeFileSpy.calls.all()[0].args[1]).toEqual(mockMinfiedResponse.code); | ||
expect(writeFileSpy.calls.all()[1].args[0]).toEqual(join(buildDir, '0.main.js.map')); | ||
expect(writeFileSpy.calls.all()[1].args[1]).toEqual(mockMinfiedResponse.map); | ||
|
||
it('should not fail if a config is not passed', () => { | ||
const context = {}; | ||
let configFile: any; | ||
expect(writeFileSpy.calls.all()[2].args[0]).toEqual(join(buildDir, '1.main.js')); | ||
expect(writeFileSpy.calls.all()[2].args[1]).toEqual(mockMinfiedResponse.code); | ||
expect(writeFileSpy.calls.all()[3].args[0]).toEqual(join(buildDir, '1.main.js.map')); | ||
expect(writeFileSpy.calls.all()[3].args[1]).toEqual(mockMinfiedResponse.map); | ||
|
||
return uglifyjs.uglifyjs(context).then(() => { | ||
expect(configUtil.getUserConfigFile).toHaveBeenCalledWith(context, uglifyjs.taskInfo, configFile); | ||
expect(workerClient.runWorker).toHaveBeenCalledWith('uglifyjs', 'uglifyjsWorker', context, 'fileContents'); | ||
expect(writeFileSpy.calls.all()[4].args[0]).toEqual(join(buildDir, 'main.js')); | ||
expect(writeFileSpy.calls.all()[4].args[1]).toEqual(mockMinfiedResponse.code); | ||
expect(writeFileSpy.calls.all()[5].args[0]).toEqual(join(buildDir, 'main.js.map')); | ||
expect(writeFileSpy.calls.all()[5].args[1]).toEqual(mockMinfiedResponse.map); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.