forked from reworkcss/css
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-tests.js
47 lines (40 loc) · 1.53 KB
/
generate-tests.js
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
// Generates missing output source and AST files for the test cases
// IMPORTANT: Always verify the generated files when using this!
var fs = require('fs');
var path = require('path');
var parse = require('./').parse;
var stringify = require('./').stringify;
var casesDir = path.join(__dirname, 'test', 'cases');
var cases = fs.readdirSync(casesDir)
.map(function(f) { return path.join(casesDir, f); });
cases.forEach(function(dir) {
var inputFile = path.join(dir, 'input.css');
if (!fs.existsSync(inputFile))
throw new Error('Missing input file ' + inputFile);
var input = fs.readFileSync(inputFile, 'utf8');
var parsed;
try {
parsed = parse(input, { source: 'input.css' });
} catch(e) {
console.log('Failed to parse', inputFile);
throw e;
}
var outputFile = path.join(dir, 'output.css');
if (!fs.existsSync(outputFile)) {
console.log('Generating', outputFile);
var output = stringify(parsed);
fs.writeFileSync(outputFile, output, 'utf8');
}
var compressedFile = path.join(dir, 'compressed.css');
if (!fs.existsSync(compressedFile)) {
console.log('Generating', compressedFile);
var compressed = stringify(parsed, { compress: true });
fs.writeFileSync(compressedFile, compressed, 'utf8');
}
var astFile = path.join(dir, 'ast.json');
if (!fs.existsSync(astFile)) {
console.log('Generating', astFile);
var ast = JSON.stringify(parsed, null, ' ');
fs.writeFileSync(astFile, ast, 'utf8');
}
});