|
| 1 | +/** |
| 2 | + * @file Smoke tests for verifying the npm package bundle includes all required files. |
| 3 | + * |
| 4 | + * These tests ensure that critical files like trust-level exclusions |
| 5 | + * are properly bundled in the dist folder and will be available |
| 6 | + * when the package is published to npm. |
| 7 | + */ |
| 8 | +import { |
| 9 | + describe, |
| 10 | + it, |
| 11 | + expect, |
| 12 | +} from 'vitest'; |
| 13 | +import path from 'path'; |
| 14 | +import { existsSync, readFileSync } from 'fs'; |
| 15 | + |
| 16 | +const __dirname = path.dirname(new URL(import.meta.url).pathname); |
| 17 | +const distDir = path.join(__dirname, '../dist'); |
| 18 | + |
| 19 | +describe('Bundle smoke tests', () => { |
| 20 | + describe('Trust-level exclusion files', () => { |
| 21 | + const trustLevelsDir = path.join(distDir, 'utils/trust-levels'); |
| 22 | + |
| 23 | + const trustLevelFiles = [ |
| 24 | + 'exclusions-low.txt', |
| 25 | + 'exclusions-high.txt', |
| 26 | + 'exclusions-full.txt', |
| 27 | + ]; |
| 28 | + |
| 29 | + it('trust-levels directory should exist in dist', () => { |
| 30 | + expect(existsSync(trustLevelsDir)).toBe(true); |
| 31 | + }); |
| 32 | + |
| 33 | + trustLevelFiles.forEach((filename) => { |
| 34 | + describe(`${filename}`, () => { |
| 35 | + const filePath = path.join(trustLevelsDir, filename); |
| 36 | + |
| 37 | + it('should exist', () => { |
| 38 | + expect(existsSync(filePath)).toBe(true); |
| 39 | + }); |
| 40 | + |
| 41 | + it('should not be empty', () => { |
| 42 | + const content = readFileSync(filePath, 'utf-8'); |
| 43 | + expect(content.length).toBeGreaterThan(0); |
| 44 | + }); |
| 45 | + }); |
| 46 | + }); |
| 47 | + |
| 48 | + it('exclusions-low.txt should contain #$# exclusion pattern', () => { |
| 49 | + const filePath = path.join(trustLevelsDir, 'exclusions-low.txt'); |
| 50 | + const content = readFileSync(filePath, 'utf-8'); |
| 51 | + // #$# is a CSS injection rule marker that should be excluded for low trust level |
| 52 | + expect(content).toContain('#$#'); |
| 53 | + }); |
| 54 | + |
| 55 | + it('exclusions-low.txt should contain #%# exclusion pattern', () => { |
| 56 | + const filePath = path.join(trustLevelsDir, 'exclusions-low.txt'); |
| 57 | + const content = readFileSync(filePath, 'utf-8'); |
| 58 | + // #%# is a JS injection rule marker that should be excluded for low trust level |
| 59 | + expect(content).toContain('#%#'); |
| 60 | + }); |
| 61 | + |
| 62 | + it('exclusions-low.txt should contain $replace exclusion pattern', () => { |
| 63 | + const filePath = path.join(trustLevelsDir, 'exclusions-low.txt'); |
| 64 | + const content = readFileSync(filePath, 'utf-8'); |
| 65 | + // $replace modifier should be excluded for low trust level |
| 66 | + expect(content).toContain('$replace'); |
| 67 | + }); |
| 68 | + }); |
| 69 | + |
| 70 | + describe('Schema files', () => { |
| 71 | + const schemasDir = path.join(distDir, 'schemas'); |
| 72 | + |
| 73 | + it('schemas directory should exist in dist', () => { |
| 74 | + expect(existsSync(schemasDir)).toBe(true); |
| 75 | + }); |
| 76 | + |
| 77 | + it('filters.schema.json should exist', () => { |
| 78 | + const filePath = path.join(schemasDir, 'filters.schema.json'); |
| 79 | + expect(existsSync(filePath)).toBe(true); |
| 80 | + }); |
| 81 | + |
| 82 | + it('filters_i18n.schema.json should exist', () => { |
| 83 | + const filePath = path.join(schemasDir, 'filters_i18n.schema.json'); |
| 84 | + expect(existsSync(filePath)).toBe(true); |
| 85 | + }); |
| 86 | + }); |
| 87 | + |
| 88 | + describe('Main entry points', () => { |
| 89 | + it('dist/index.js (ESM) should exist', () => { |
| 90 | + const filePath = path.join(distDir, 'index.js'); |
| 91 | + expect(existsSync(filePath)).toBe(true); |
| 92 | + }); |
| 93 | + |
| 94 | + it('dist/index.cjs (CommonJS) should exist', () => { |
| 95 | + const filePath = path.join(distDir, 'index.cjs'); |
| 96 | + expect(existsSync(filePath)).toBe(true); |
| 97 | + }); |
| 98 | + }); |
| 99 | +}); |
0 commit comments