|
1 |
| -"use strict"; |
| 1 | +'use strict'; |
2 | 2 |
|
3 | 3 | /*globals describe it */
|
4 | 4 |
|
5 |
| -var assert = require("assert"); |
6 |
| -var fs = require("fs"); |
7 |
| -var path = require("path"); |
8 |
| -var postcss = require("postcss"); |
9 |
| -var processor = require("../src"); |
| 5 | +var assert = require('assert'); |
| 6 | +var fs = require('fs'); |
| 7 | +var path = require('path'); |
| 8 | +var postcss = require('postcss'); |
| 9 | +var processor = require('../src'); |
10 | 10 |
|
11 | 11 | function generateInvalidCSS(css) {
|
12 | 12 | css.walkDecls(function(decl) {
|
13 |
| - decl.value = decl.value.replace(/_colon_/g, ":"); // because using a : in the tests would make it invalid CSS. |
| 13 | + decl.value = decl.value.replace(/_colon_/g, ':'); // because using a : in the tests would make it invalid CSS. |
14 | 14 | });
|
15 | 15 | }
|
16 | 16 |
|
17 | 17 | function normalize(str) {
|
18 |
| - return str.replace(/\r\n?/g, "\n").replace(/\n$/, ''); |
| 18 | + return str.replace(/\r\n?/g, '\n').replace(/\n$/, ''); |
19 | 19 | }
|
20 | 20 |
|
21 | 21 | var generateScopedName = processor.generateScopedName;
|
22 | 22 |
|
23 |
| -describe("test-cases", function() { |
24 |
| - var testDir = path.join(__dirname, "test-cases"); |
| 23 | +describe('test-cases', function() { |
| 24 | + var testDir = path.join(__dirname, 'test-cases'); |
25 | 25 | fs.readdirSync(testDir).forEach(function(testCase) {
|
26 |
| - if(fs.existsSync(path.join(testDir, testCase, "source.css"))) { |
27 |
| - it("should " + testCase.replace(/-/g, " "), function() { |
28 |
| - var input = normalize(fs.readFileSync(path.join(testDir, testCase, "source.css"), "utf-8")); |
| 26 | + if(fs.existsSync(path.join(testDir, testCase, 'source.css'))) { |
| 27 | + it('should ' + testCase.replace(/-/g, ' '), function() { |
| 28 | + var input = normalize(fs.readFileSync(path.join(testDir, testCase, 'source.css'), 'utf-8')); |
29 | 29 | var expected, expectedError;
|
30 |
| - if(fs.existsSync(path.join(testDir, testCase, "expected.error.txt"))) { |
31 |
| - expectedError = normalize(fs.readFileSync(path.join(testDir, testCase, "expected.error.txt"), "utf-8")) |
32 |
| - .split("\n")[0]; |
| 30 | + if(fs.existsSync(path.join(testDir, testCase, 'expected.error.txt'))) { |
| 31 | + expectedError = normalize(fs.readFileSync(path.join(testDir, testCase, 'expected.error.txt'), 'utf-8')) |
| 32 | + .split('\n')[0]; |
33 | 33 | } else {
|
34 |
| - expected = normalize(fs.readFileSync(path.join(testDir, testCase, "expected.css"), "utf-8")); |
| 34 | + expected = normalize(fs.readFileSync(path.join(testDir, testCase, 'expected.css'), 'utf-8')); |
35 | 35 | }
|
36 |
| - var config = { from: "/input" }; |
| 36 | + var config = { from: '/input' }; |
37 | 37 | var options = {
|
38 | 38 | generateScopedName: function(exportedName, inputPath) {
|
39 |
| - var normalizedPath = inputPath.replace(/^[A-Z]:/, ""); |
| 39 | + var normalizedPath = inputPath.replace(/^[A-Z]:/, ''); |
40 | 40 | return generateScopedName(exportedName, normalizedPath);
|
41 | 41 | }
|
42 | 42 | };
|
43 |
| - if(fs.existsSync(path.join(testDir, testCase, "config.json"))) { |
44 |
| - config = JSON.parse(fs.readFileSync(path.join(testDir, testCase, "config.json"), "utf-8")); |
| 43 | + if(fs.existsSync(path.join(testDir, testCase, 'config.json'))) { |
| 44 | + config = JSON.parse(fs.readFileSync(path.join(testDir, testCase, 'config.json'), 'utf-8')); |
45 | 45 | }
|
46 |
| - if(fs.existsSync(path.join(testDir, testCase, "options.js"))) { |
47 |
| - options = require(path.join(testDir, testCase, "options.js")); |
| 46 | + if(fs.existsSync(path.join(testDir, testCase, 'options.js'))) { |
| 47 | + options = require(path.join(testDir, testCase, 'options.js')); |
48 | 48 | }
|
49 | 49 | var pipeline = postcss([generateInvalidCSS, processor(options)]);
|
50 | 50 | if(expectedError) {
|
|
0 commit comments