diff options
author | XhmikosR <xhmikosr@gmail.com> | 2019-02-17 15:52:17 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-17 15:52:17 +0300 |
commit | 8d7f4cdae3ea77945d5be84b24db527fc78a5170 (patch) | |
tree | 25e62b988cbf32ccda34274fb31154cf5541a517 /test | |
parent | 178ff7d7d75abddc8434b30a4c3775c21bedecb6 (diff) |
Refactor tests. (#90)
Diffstat (limited to 'test')
-rw-r--r-- | test/expected/test-1.css (renamed from test/result/test-1.css) | 0 | ||||
-rw-r--r-- | test/expected/test-10.css (renamed from test/result/test-10.css) | 0 | ||||
-rw-r--r-- | test/expected/test-2.css (renamed from test/result/test-2.css) | 0 | ||||
-rw-r--r-- | test/expected/test-3.css (renamed from test/result/test-3.css) | 0 | ||||
-rw-r--r-- | test/expected/test-4.css (renamed from test/result/test-4.css) | 0 | ||||
-rw-r--r-- | test/expected/test-5.css (renamed from test/result/test-5.css) | 0 | ||||
-rw-r--r-- | test/expected/test-6.css (renamed from test/result/test-6.css) | 0 | ||||
-rw-r--r-- | test/expected/test-7.css (renamed from test/result/test-7.css) | 0 | ||||
-rw-r--r-- | test/expected/test-8.css (renamed from test/result/test-8.css) | 0 | ||||
-rw-r--r-- | test/expected/test-9.css (renamed from test/result/test-9.css) | 0 | ||||
-rw-r--r-- | test/lib/result.js | 39 | ||||
-rw-r--r-- | test/lib/tests.js | 44 | ||||
-rw-r--r-- | test/test.js | 11 | ||||
-rw-r--r-- | test/tests.json | 42 |
14 files changed, 76 insertions, 60 deletions
diff --git a/test/result/test-1.css b/test/expected/test-1.css index 3bed4b0..3bed4b0 100644 --- a/test/result/test-1.css +++ b/test/expected/test-1.css diff --git a/test/result/test-10.css b/test/expected/test-10.css index c84a744..c84a744 100644 --- a/test/result/test-10.css +++ b/test/expected/test-10.css diff --git a/test/result/test-2.css b/test/expected/test-2.css index 4f7e02b..4f7e02b 100644 --- a/test/result/test-2.css +++ b/test/expected/test-2.css diff --git a/test/result/test-3.css b/test/expected/test-3.css index 401fbec..401fbec 100644 --- a/test/result/test-3.css +++ b/test/expected/test-3.css diff --git a/test/result/test-4.css b/test/expected/test-4.css index ce0e868..ce0e868 100644 --- a/test/result/test-4.css +++ b/test/expected/test-4.css diff --git a/test/result/test-5.css b/test/expected/test-5.css index 461b32b..461b32b 100644 --- a/test/result/test-5.css +++ b/test/expected/test-5.css diff --git a/test/result/test-6.css b/test/expected/test-6.css index d4330c1..d4330c1 100644 --- a/test/result/test-6.css +++ b/test/expected/test-6.css diff --git a/test/result/test-7.css b/test/expected/test-7.css index ae43db2..ae43db2 100644 --- a/test/result/test-7.css +++ b/test/expected/test-7.css diff --git a/test/result/test-8.css b/test/expected/test-8.css index 910e037..910e037 100644 --- a/test/result/test-8.css +++ b/test/expected/test-8.css diff --git a/test/result/test-9.css b/test/expected/test-9.css index c84a744..c84a744 100644 --- a/test/result/test-9.css +++ b/test/expected/test-9.css diff --git a/test/lib/result.js b/test/lib/result.js index add6340..d3e3e11 100644 --- a/test/lib/result.js +++ b/test/lib/result.js @@ -2,6 +2,7 @@ // Packages const fs = require('fs'); +const path = require('path'); const prettier = require('prettier'); const sass = require('node-sass'); const less = require('less'); @@ -10,36 +11,46 @@ const stylus = require('stylus'); // Postcss const postcss = require('postcss'); const rfs = require('../..'); -const postcsstests = require('../postcss/tests.js'); - -// Strings -const encoding = 'utf8'; -const dir = `${__dirname}/../`; +const postcssTests = require('../postcss/tests.js'); // Functions -const format = css => prettier.format(css, {parser: 'css'}).replace(/(\n)(\n)/g, '$1'); -const getFileContent = (folder, id, ext) => fs.readFileSync(`${dir}${folder}/${id}.${ext}`, {encoding}); +function format(css) { + return prettier.format(css, {parser: 'css'}).replace(/(\n)(\n)/g, '$1'); +} + +function getFileContent(folder, id, ext) { + return fs.readFileSync(path.join(__dirname, `../${folder}/${id}.${ext}`), 'utf8'); +} -const postcsscss = getFileContent('postcss', 'main', 'css'); +const postcssCss = getFileContent('postcss', 'main', 'css'); // Exports module.exports = { // Return formatted expected result - expected: id => format(getFileContent('result', id, 'css')), + expected: id => format(getFileContent('expected', id, 'css')), // Return parsed css - sass: id => format(sass.renderSync({file: `${dir}sass/${id}.scss`}).css.toString(encoding)), + sass: id => { + return format(sass.renderSync({ + file: path.join(__dirname, `../sass/${id}.scss`) + }).css.toString('utf8')); + }, // Return parsed css less: id => { - return less.render(getFileContent('less', id, 'less'), {paths: [dir + 'less'], syncImport: true}).then(result => { + return less.render(getFileContent('less', id, 'less'), { + paths: [path.join(__dirname, '../less')], + syncImport: true + }).then(result => { return format(result.css); }); }, stylus: id => { let formattedCSS = ''; - stylus.render(getFileContent('stylus', id, 'styl'), {filename: `${dir}stylus/${id}.styl`}, (err, css) => { + stylus.render(getFileContent('stylus', id, 'styl'), { + filename: path.join(__dirname, `../stylus/${id}.styl`) + }, (err, css) => { if (err) { throw err; } @@ -49,5 +60,7 @@ module.exports = { return formattedCSS; }, - postcss: id => format(postcss(rfs(postcsstests[id])).process(postcsscss).css) + postcss: id => { + return format(postcss(rfs(postcssTests[id])).process(postcssCss).css); + } }; diff --git a/test/lib/tests.js b/test/lib/tests.js deleted file mode 100644 index 45dc97d..0000000 --- a/test/lib/tests.js +++ /dev/null @@ -1,44 +0,0 @@ -'use strict'; - -module.exports = [ - { - id: 'test-1', - name: 'Default build' - }, - { - id: 'test-2', - name: 'Disable responsive font size' - }, - { - id: 'test-3', - name: 'Disabled class' - }, - { - id: 'test-4', - name: 'Enable class' - }, - { - id: 'test-5', - name: 'Change breakpoint unit to em' - }, - { - id: 'test-6', - name: 'Change base font size' - }, - { - id: 'test-7', - name: 'Change font size unit' - }, - { - id: 'test-8', - name: 'Enable two dimensional' - }, - { - id: 'test-9', - name: 'Go loco with the config' - }, - { - id: 'test-10', - name: 'Include mixins multiple times' - } -]; diff --git a/test/test.js b/test/test.js index 9296599..e3f5210 100644 --- a/test/test.js +++ b/test/test.js @@ -3,10 +3,15 @@ 'use strict'; const assert = require('assert'); -const tests = require('./lib/tests.js'); - -const styles = ['Less', 'Sass', 'Stylus', 'PostCSS']; const result = require('./lib/result.js'); +const tests = require('./tests.json'); + +const styles = [ + 'Less', + 'Sass', + 'Stylus', + 'Postcss' +]; styles.forEach(style => { describe(style, () => { diff --git a/test/tests.json b/test/tests.json new file mode 100644 index 0000000..f61f030 --- /dev/null +++ b/test/tests.json @@ -0,0 +1,42 @@ +[ + { + "id": "test-1", + "name": "Default build" + }, + { + "id": "test-2", + "name": "Disable responsive font size" + }, + { + "id": "test-3", + "name": "Disabled class" + }, + { + "id": "test-4", + "name": "Enable class" + }, + { + "id": "test-5", + "name": "Change breakpoint unit to em" + }, + { + "id": "test-6", + "name": "Change base font size" + }, + { + "id": "test-7", + "name": "Change font size unit" + }, + { + "id": "test-8", + "name": "Enable two dimensional" + }, + { + "id": "test-9", + "name": "Go loco with the config" + }, + { + "id": "test-10", + "name": "Include mixins multiple times" + } +] |