|
| 1 | +import {afterEach, beforeEach, describe, expect, it} from "vitest"; |
| 2 | +import { |
| 3 | + addCodePushupConfigFile, cleanTestFolder, |
| 4 | + executeCliCollectForPlugin, |
| 5 | + getRelativePathToPluginDist, omitVariableReportData, |
| 6 | + readReportJson |
| 7 | +} from "testing-utils"; |
| 8 | +import {resolve} from "path"; |
| 9 | +import {Report, reportSchema} from "@code-pushup/models"; |
| 10 | + |
| 11 | +describe('execute-plugin-bundle-size', () => { |
| 12 | + const baseDir = resolve('tmp/e2e/execute-plugin-bundle-size'); |
| 13 | + |
| 14 | + beforeEach(async () => { |
| 15 | + await addCodePushupConfigFile( { |
| 16 | + fileImports: [`import {bundleSizePlugin} from "${getRelativePathToPluginDist(baseDir, 'bundle-size')}";`], |
| 17 | + pluginStrings: ['bundleSizePlugin()'], |
| 18 | + targetFolder: baseDir |
| 19 | + }); |
| 20 | + }); |
| 21 | + |
| 22 | + afterEach(async () => { |
| 23 | + await cleanTestFolder(baseDir); |
| 24 | + }); |
| 25 | + |
| 26 | + it('should run bundle-size plugin and create valid report.json', async () => { |
| 27 | + const { code, stderr } = await executeCliCollectForPlugin('bundle-size', {}, baseDir); |
| 28 | + expect(code).toBe(0); |
| 29 | + |
| 30 | + const report: Report = await readReportJson(baseDir); |
| 31 | + expect(() => reportSchema.parse(report)).not.toThrow(); |
| 32 | + expect(omitVariableReportData(report)).toMatchSnapshot(); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should run bundle-size plugin with the correct slug and audits in report.json', async () => { |
| 36 | + const { code, stderr } = await executeCliCollectForPlugin('bundle-size', {}, baseDir); |
| 37 | + expect(code).toBe(0); |
| 38 | + |
| 39 | + const report: Report = await readReportJson(baseDir); |
| 40 | + expect(report.plugins.at(0)?.slug).toBe('bundle-size'); |
| 41 | + expect(report.plugins.at(0)?.audits.length).toBe(1); |
| 42 | + expect(report.plugins.at(0)?.audits.at(0)?.slug).toBe('bundle-size'); |
| 43 | + |
| 44 | + }); |
| 45 | +}); |
0 commit comments