|
| 1 | +const { bootstrap, getOutputProduction } = require('../../utils'); |
| 2 | +const fs = require('fs-extra'); |
| 3 | +const path = require('path'); |
| 4 | +const Semaphore = require('async-sema'); |
| 5 | +const tempy = require('tempy'); |
| 6 | + |
| 7 | +describe('webpack message formatting', () => { |
| 8 | + const semaphore = new Semaphore(1, { capacity: Infinity }); |
| 9 | + let testDirectory; |
| 10 | + beforeAll(async () => { |
| 11 | + testDirectory = tempy.directory(); |
| 12 | + await bootstrap({ directory: testDirectory, template: __dirname }); |
| 13 | + }); |
| 14 | + beforeEach(async () => { |
| 15 | + await semaphore.acquire(); |
| 16 | + }); |
| 17 | + afterEach(async () => { |
| 18 | + fs.removeSync(path.join(testDirectory, 'src', 'App.js')); |
| 19 | + semaphore.release(); |
| 20 | + }); |
| 21 | + |
| 22 | + it('formats babel syntax error', async () => { |
| 23 | + fs.copySync( |
| 24 | + path.join(__dirname, 'src', 'AppBabel.js'), |
| 25 | + path.join(testDirectory, 'src', 'App.js') |
| 26 | + ); |
| 27 | + |
| 28 | + const response = await getOutputProduction({ directory: testDirectory }); |
| 29 | + expect(response).toMatchSnapshot(); |
| 30 | + }); |
| 31 | + |
| 32 | + xit('formats css syntax error', async () => { |
| 33 | + // TODO: fix me! |
| 34 | + fs.copySync( |
| 35 | + path.join(__dirname, 'src', 'AppCss.js'), |
| 36 | + path.join(testDirectory, 'src', 'App.js') |
| 37 | + ); |
| 38 | + |
| 39 | + const response = await getOutputProduction({ directory: testDirectory }); |
| 40 | + expect(response).toMatchSnapshot(); |
| 41 | + }); |
| 42 | + |
| 43 | + xit('formats unknown export', async () => { |
| 44 | + // TODO: fix me! |
| 45 | + fs.copySync( |
| 46 | + path.join(__dirname, 'src', 'AppUnknownExport.js'), |
| 47 | + path.join(testDirectory, 'src', 'App.js') |
| 48 | + ); |
| 49 | + |
| 50 | + const response = await getOutputProduction({ directory: testDirectory }); |
| 51 | + expect(response).toMatchSnapshot(); |
| 52 | + }); |
| 53 | + |
| 54 | + xit('formats missing package', async () => { |
| 55 | + // TODO: fix me! |
| 56 | + fs.copySync( |
| 57 | + path.join(__dirname, 'src', 'AppMissingPackage.js'), |
| 58 | + path.join(testDirectory, 'src', 'App.js') |
| 59 | + ); |
| 60 | + |
| 61 | + const response = await getOutputProduction({ directory: testDirectory }); |
| 62 | + expect(response).toMatchSnapshot(); |
| 63 | + }); |
| 64 | + |
| 65 | + it('formats eslint warning', async () => { |
| 66 | + fs.copySync( |
| 67 | + path.join(__dirname, 'src', 'AppLintWarning.js'), |
| 68 | + path.join(testDirectory, 'src', 'App.js') |
| 69 | + ); |
| 70 | + |
| 71 | + const response = await getOutputProduction({ directory: testDirectory }); |
| 72 | + const sizeIndex = response.stdout.indexOf('File sizes after gzip'); |
| 73 | + if (sizeIndex !== -1) { |
| 74 | + response.stdout = response.stdout.substring(0, sizeIndex); |
| 75 | + } |
| 76 | + expect(response).toMatchSnapshot(); |
| 77 | + }); |
| 78 | + |
| 79 | + it('formats eslint error', async () => { |
| 80 | + fs.copySync( |
| 81 | + path.join(__dirname, 'src', 'AppLintError.js'), |
| 82 | + path.join(testDirectory, 'src', 'App.js') |
| 83 | + ); |
| 84 | + |
| 85 | + const response = await getOutputProduction({ directory: testDirectory }); |
| 86 | + expect(response).toMatchSnapshot(); |
| 87 | + }); |
| 88 | +}); |
0 commit comments