|
| 1 | +import 'mocha'; |
| 2 | +import * as chai from 'chai'; |
| 3 | +const expect = chai.expect; |
| 4 | +import { exec, cd } from 'shelljs'; |
| 5 | +import * as AdmZip from 'adm-zip'; |
| 6 | +import { resolve } from 'path'; |
| 7 | + |
| 8 | +describe('Fixture 6: specifying a different archive name, bundling multiple assets, adding a WEB-INF folder and adding additional elements', function () { |
| 9 | + let webpackOutput: string; |
| 10 | + let archiveEntries: string[]; |
| 11 | + |
| 12 | + before('Run webpack build', function () { |
| 13 | + cd(resolve(__dirname)); |
| 14 | + const { code, stderr, stdout } = exec('yarn run build'); |
| 15 | + |
| 16 | + if (code != 0) return expect.fail(stderr, '', 'Webpack build failed'); |
| 17 | + |
| 18 | + webpackOutput = stdout; |
| 19 | + }); |
| 20 | + |
| 21 | + before('Get archive entries', function () { |
| 22 | + const zip = new AdmZip(resolve(__dirname, 'dist', 'archive.war')); |
| 23 | + |
| 24 | + archiveEntries = zip.getEntries().map(entry => entry.entryName); |
| 25 | + }); |
| 26 | + |
| 27 | + describe('Webpack output', function () { |
| 28 | + it('Should output "WAR Archive"', function () { |
| 29 | + expect(webpackOutput).to.contain('WAR Archive'); |
| 30 | + }); |
| 31 | + |
| 32 | + it('Should output the correct archive information line', function () { |
| 33 | + expect(webpackOutput).to.contain('archive.war'); |
| 34 | + expect(webpackOutput).to.contain('[written]'); |
| 35 | + expect(webpackOutput).to.match(/[\s\S]archive\.war\t\d+\.?\d* (B|KB|MB)[\s\S]/); |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | + describe('Archive content', function () { |
| 40 | + it('Should create a archive which contains the correct assets', function () { |
| 41 | + expect(archiveEntries).to.include.members(['file1.js', 'file2.js', 'file3.js', 'dir1/file4.js']); |
| 42 | + }); |
| 43 | + |
| 44 | + it('Should create a archive which contains the correct additional elements', function () { |
| 45 | + expect(archiveEntries).to.include.members(['file1.js', 'META-INF/context.xml', 'pom.xml', 'dir/man.xml']); |
| 46 | + }); |
| 47 | + |
| 48 | + it('Should create a archive which contains the correct WEB-INF elements', function () { |
| 49 | + expect(archiveEntries).to.include.members(['file1.js', 'WEB-INF/web.xml']); |
| 50 | + }); |
| 51 | + }); |
| 52 | +}); |
0 commit comments