|
| 1 | +import { join } from 'path'; |
| 2 | + |
| 3 | +import * as webpack from './webpack'; |
| 4 | +import { FileCache } from './util/file-cache'; |
| 5 | +import * as helpers from './util/helpers'; |
| 6 | + |
| 7 | +describe('Webpack Task', () => { |
| 8 | + describe('writeBundleFilesToDisk', () => { |
| 9 | + it('should write all build artifacts to disk except css', () => { |
| 10 | + const appDir = join('some', 'fake', 'dir', 'myApp'); |
| 11 | + const buildDir = join(appDir, 'www', 'build'); |
| 12 | + |
| 13 | + const context = { |
| 14 | + fileCache: new FileCache(), |
| 15 | + buildDir: buildDir |
| 16 | + }; |
| 17 | + |
| 18 | + const fileOnePath = join(buildDir, 'main.js'); |
| 19 | + const fileTwoPath = join(buildDir, 'main.js.map'); |
| 20 | + const fileThreePath = join(buildDir, '0.main.js'); |
| 21 | + const fileFourPath = join(buildDir, '0.main.js.map'); |
| 22 | + const fileFivePath = join(buildDir, '1.main.js'); |
| 23 | + const fileSixPath = join(buildDir, '1.main.js.map'); |
| 24 | + const fileSevenPath = join(appDir, 'pages', 'page-one.ts'); |
| 25 | + const fileEightPath = join(appDir, 'pages', 'page-one.js'); |
| 26 | + const fileNinePath = join(buildDir, 'main.css'); |
| 27 | + const fileTenPath = join(buildDir, 'main.css.map'); |
| 28 | + const fileElevenPath = join(buildDir, 'secondary.css'); |
| 29 | + const fileTwelvePath = join(buildDir, 'secondary.css.map'); |
| 30 | + |
| 31 | + context.fileCache.set(fileOnePath, { path: fileOnePath, content: fileOnePath + 'content'}); |
| 32 | + context.fileCache.set(fileTwoPath, { path: fileTwoPath, content: fileTwoPath + 'content'}); |
| 33 | + context.fileCache.set(fileThreePath, { path: fileThreePath, content: fileThreePath + 'content'}); |
| 34 | + context.fileCache.set(fileFourPath, { path: fileFourPath, content: fileFourPath + 'content'}); |
| 35 | + context.fileCache.set(fileFivePath, { path: fileFivePath, content: fileFivePath + 'content'}); |
| 36 | + context.fileCache.set(fileSixPath, { path: fileSixPath, content: fileSixPath + 'content'}); |
| 37 | + context.fileCache.set(fileSevenPath, { path: fileSevenPath, content: fileSevenPath + 'content'}); |
| 38 | + context.fileCache.set(fileEightPath, { path: fileEightPath, content: fileEightPath + 'content'}); |
| 39 | + context.fileCache.set(fileNinePath, { path: fileNinePath, content: fileNinePath + 'content'}); |
| 40 | + context.fileCache.set(fileTenPath, { path: fileTenPath, content: fileTenPath + 'content'}); |
| 41 | + context.fileCache.set(fileElevenPath, { path: fileElevenPath, content: fileElevenPath + 'content'}); |
| 42 | + context.fileCache.set(fileTwelvePath, { path: fileTwelvePath, content: fileTwelvePath + 'content'}); |
| 43 | + |
| 44 | + const writeFileSpy = spyOn(helpers, helpers.writeFileAsync.name).and.returnValue(Promise.resolve()); |
| 45 | + |
| 46 | + const promise = webpack.writeBundleFilesToDisk(context); |
| 47 | + |
| 48 | + return promise.then(() => { |
| 49 | + expect(writeFileSpy).toHaveBeenCalledTimes(6); |
| 50 | + expect(writeFileSpy.calls.all()[0].args[0]).toEqual(fileOnePath); |
| 51 | + expect(writeFileSpy.calls.all()[0].args[1]).toEqual(fileOnePath + 'content'); |
| 52 | + |
| 53 | + expect(writeFileSpy.calls.all()[1].args[0]).toEqual(fileTwoPath); |
| 54 | + expect(writeFileSpy.calls.all()[1].args[1]).toEqual(fileTwoPath + 'content'); |
| 55 | + |
| 56 | + expect(writeFileSpy.calls.all()[2].args[0]).toEqual(fileThreePath); |
| 57 | + expect(writeFileSpy.calls.all()[2].args[1]).toEqual(fileThreePath + 'content'); |
| 58 | + |
| 59 | + expect(writeFileSpy.calls.all()[3].args[0]).toEqual(fileFourPath); |
| 60 | + expect(writeFileSpy.calls.all()[3].args[1]).toEqual(fileFourPath + 'content'); |
| 61 | + |
| 62 | + expect(writeFileSpy.calls.all()[4].args[0]).toEqual(fileFivePath); |
| 63 | + expect(writeFileSpy.calls.all()[4].args[1]).toEqual(fileFivePath + 'content'); |
| 64 | + |
| 65 | + expect(writeFileSpy.calls.all()[5].args[0]).toEqual(fileSixPath); |
| 66 | + expect(writeFileSpy.calls.all()[5].args[1]).toEqual(fileSixPath + 'content'); |
| 67 | + }); |
| 68 | + }); |
| 69 | + }); |
| 70 | +}); |
0 commit comments