-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate-fixtures.js
More file actions
109 lines (93 loc) · 3.47 KB
/
validate-fixtures.js
File metadata and controls
109 lines (93 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env node
/**
* Fixture Test Runner
*
* This script helps validate CSS if() polyfill fixtures by running them through
* a real browser environment using Playwright.
*
* Usage:
* node scripts/validate-fixtures.js [fixture-name]
*
* Examples:
* node scripts/validate-fixtures.js # Run all fixtures
* node scripts/validate-fixtures.js basic-media # Run specific fixture
*/
import { execSync } from 'node:child_process';
import { readdirSync } from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import { fileURLToPath } from 'node:url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const fixturesDir = path.join(__dirname, '..', 'test', 'fixtures');
function getAvailableFixtures() {
const files = readdirSync(fixturesDir);
const inputFiles = files.filter((file) => file.endsWith('.input.css'));
return inputFiles.map((file) => file.replace('.input.css', ''));
}
function runFixtureTests(fixtureName = null) {
console.log('🎭 CSS if() Polyfill Fixture Validation');
console.log('==========================================\n');
const availableFixtures = getAvailableFixtures();
if (fixtureName) {
if (!availableFixtures.includes(fixtureName)) {
console.error(`❌ Fixture "${fixtureName}" not found.`);
console.log('\nAvailable fixtures:');
for (const name of availableFixtures) console.log(` - ${name}`);
process.exit(1);
}
console.log(`🧪 Running fixture: ${fixtureName}\n`);
} else {
console.log(`🧪 Running all ${availableFixtures.length} fixtures:\n`);
for (const name of availableFixtures) console.log(` ✓ ${name}`);
console.log('');
}
try {
// Run Playwright tests
const grepPattern = fixtureName
? `--grep "validates ${fixtureName} fixture"`
: '';
const command = `npx playwright test test/fixtures-validation/fixture-validation.test.js --config=test/fixtures-validation/fixture-validation.playwright.config.js ${grepPattern}`;
console.log('🚀 Starting browser-based validation...\n');
execSync(command, {
stdio: 'inherit',
cwd: path.join(__dirname, '..')
});
console.log('\n✅ All fixture validations passed!');
console.log('\nThis means:');
console.log(' • Your polyfill correctly transforms input CSS');
console.log(' • Browser rendering matches expected output');
console.log(' • Media queries work responsively');
console.log(' • @supports queries function properly');
} catch {
console.error('\n❌ Fixture validation failed!');
console.error('Please check the test output above for details.');
process.exit(1);
}
}
// Parse command line arguments
const fixtureName = process.argv[2];
// Show help if requested
if (fixtureName === '--help' || fixtureName === '-h') {
console.log('CSS if() Polyfill Fixture Validator\n');
console.log('Usage:');
console.log(' node scripts/validate-fixtures.js [fixture-name]\n');
console.log('Examples:');
console.log(
' node scripts/validate-fixtures.js # Run all fixtures'
);
console.log(
' node scripts/validate-fixtures.js basic-media # Run specific fixture'
);
console.log(
' node scripts/validate-fixtures.js --list # List available fixtures\n'
);
process.exit(0);
}
// List fixtures if requested
if (fixtureName === '--list' || fixtureName === '-l') {
console.log('Available fixtures:');
for (const name of getAvailableFixtures()) console.log(` ${name}`);
process.exit(0);
}
// Run the tests
runFixtureTests(fixtureName);