Skip to content

Commit 9785226

Browse files
evilebottnawimichael-ciniawsky
authored andcommitted
test: refactor using .config.js (JS) for test configs (#230)
1 parent 12c19b9 commit 9785226

31 files changed

+115
-94
lines changed

test/configs/config.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
file: 'config',
3+
options: {
4+
config: {
5+
path: 'test/fixtures/config/postcss.config.js',
6+
ctx: { plugin: false }
7+
}
8+
}
9+
}

test/configs/config.json

-9
This file was deleted.

test/configs/error.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
file: 'error',
3+
options: {
4+
parser: 'sugarss'
5+
}
6+
}

test/configs/error.json

-6
This file was deleted.

test/configs/exec.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
file: 'exec',
3+
options: {
4+
exec: true
5+
}
6+
}

test/configs/exec.json

-6
This file was deleted.

test/configs/export.config.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
file: 'export',
3+
options: {
4+
config: {
5+
path: 'test/fixtures/config/postcss.config.js'
6+
}
7+
}
8+
}

test/configs/export.json

-8
This file was deleted.

test/configs/jss.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
file: 'jss',
3+
options: {
4+
parser: 'postcss-js'
5+
}
6+
}

test/configs/jss.json

-6
This file was deleted.

test/configs/map.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
file: 'map',
3+
options: {
4+
config: {
5+
path: 'test/fixtures'
6+
},
7+
sourceMap: 'inline'
8+
}
9+
}

test/configs/map.json

-9
This file was deleted.

test/configs/options.config.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
file: 'options',
3+
options: {
4+
parser: {},
5+
syntax: [],
6+
plugins: {}
7+
}
8+
}

test/configs/options.json

-8
This file was deleted.

test/configs/parser.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
file: 'parser',
3+
options: {
4+
parser: 'sugarss'
5+
}
6+
}

test/configs/parser.json

-6
This file was deleted.

test/configs/plugins.config.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
file: 'plugins',
3+
options: {
4+
plugins: [
5+
require('../plugin')()
6+
]
7+
}
8+
}

test/configs/plugins.fn.config.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
file: 'plugins.fn',
3+
options: {
4+
plugins: () => [
5+
require('../plugin')()
6+
]
7+
}
8+
}

test/configs/plugins.fn.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test('Plugins - {Function}', () => {
2+
const css = require('../fixtures/style.css')
3+
expect(css).toEqual('a { color: rgba(255, 0, 0, 1.0) }\n')
4+
})

test/configs/plugins.json

-6
This file was deleted.
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
file: 'sourceMap-inline',
3+
options: {
4+
config: {
5+
path: 'test/fixtures/config/postcss.config.js'
6+
},
7+
sourceMap: 'inline'
8+
}
9+
}

test/configs/sourceMap-inline.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test('Source Maps - Inline', () => {
2+
const css = require('../fixtures/style.css')
3+
expect(css).toEqual('a { color: black }\n\n/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0eWxlLmNzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxJQUFJLFlBQVksRUFBRSIsImZpbGUiOiJzdHlsZS5jc3MiLCJzb3VyY2VzQ29udGVudCI6WyJhIHsgY29sb3I6IGJsYWNrIH1cbiJdfQ== */')
4+
})

test/configs/sourceMap-true.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
file: 'sourceMap-true',
3+
options: {
4+
config: {
5+
path: 'test/fixtures/config/postcss.config.js'
6+
},
7+
sourceMap: true
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
test('Source Maps', () => {
1+
test('Source Maps - true', () => {
22
const css = require('../fixtures/style.css')
33
expect(css).toEqual('a { color: black }\n')
44
})

test/configs/sourceMap.json

-9
This file was deleted.

test/configs/stringifier.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
file: 'stringifier',
3+
options: {
4+
stringifier: 'sugarss'
5+
}
6+
}

test/configs/stringifier.json

-6
This file was deleted.

test/configs/syntax.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
file: 'syntax',
3+
options: {
4+
syntax: 'sugarss'
5+
}
6+
}

test/configs/syntax.json

-6
This file was deleted.

test/webpack.build.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ const builds = path.join(__dirname, 'builds')
1010
if (fs.existsSync(builds)) fs.remove(builds)
1111

1212
fs.readdirSync(path.join(__dirname, 'configs'))
13-
.filter((file) => path.extname(file) === '.json')
13+
.filter((file) => path.extname(file) === '.js' && path.extname(path.basename(file, '.js')) === '.config')
1414
.forEach((config) => {
15-
config = fs.readFileSync(path.join(__dirname, 'configs', config), 'utf8')
15+
config = require(path.join(__dirname, 'configs', config))
1616
config = require(path.join(__dirname, 'webpack.config.js'))(config)
1717

1818
webpack(config, () => {})

test/webpack.config.js

-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
const path = require('path')
44

55
module.exports = (config) => {
6-
config = JSON.parse(config)
7-
8-
if (config.options && config.options.plugins) {
9-
config.options.plugins = [ require('./plugin')() ]
10-
}
11-
126
return {
137
target: 'node',
148
devtool: 'source-map',

0 commit comments

Comments
 (0)