Skip to content

Commit

Permalink
test(*): simplify structure
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-ciniawsky committed Jul 9, 2018
1 parent c5df463 commit e042a6f
Show file tree
Hide file tree
Showing 15 changed files with 248 additions and 275 deletions.
8 changes: 1 addition & 7 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,5 @@ test_script:
environment:
matrix:
- nodejs_version: 'stable'
- nodejs_version: 'lts/*'
- nodejs_version: 'lts'
- nodejs_version: '6'
- nodejs_version: '4'

notifications:
- on_build_success: false
- on_build_failure: false
- on_build_status_changed: false
2 changes: 1 addition & 1 deletion src/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const plugins = (config, file) => {
plugins = config.plugins.filter(Boolean)
} else {
plugins = Object.keys(config.plugins)
.filter((plugin) =>{
.filter((plugin) => {
return config.plugins[plugin] !== false ? plugin : ''
})
.map((plugin) => {
Expand Down
2 changes: 1 addition & 1 deletion test/Errors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const postcssrc = require('../src/index.js')
test('Loading Config - {Error}', () => {
return postcssrc({}, 'test/err').catch((err) => {
expect(err.message).toMatch(
/^No PostCSS Config found in: .*\/postcss-load-config\/test\/err$/
/^No PostCSS Config found in: (.*)$/
)
})
})
Expand Down
114 changes: 114 additions & 0 deletions test/js.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
'use strict'

const path = require('path')

const postcss = require('postcss')
const postcssrc = require('../src/index.js')

const { fixture, expected } = require('./utils.js')

test('postcss.config.js - {Object} - Load Config', () => {
const ctx = {
parser: true,
syntax: true
}

return postcssrc(ctx, 'test/js/object').then((config) => {
expect(config.options.parser).toEqual(require('sugarss'))
expect(config.options.syntax).toEqual(require('sugarss'))
expect(config.options.map).toEqual(false)
expect(config.options.from).toEqual('./test/js/object/fixtures/index.css')
expect(config.options.to).toEqual('./test/js/object/expect/index.css')

expect(config.plugins.length).toEqual(2)
expect(typeof config.plugins[0]).toBe('function')
expect(typeof config.plugins[1]).toBe('function')

expect(config.file)
.toEqual(path.resolve('test/js/object', 'postcss.config.js'))
})
})

test('postcss.config.js - {Object} - Process CSS', () => {
const ctx = {
parser: false,
syntax: false
}

return postcssrc(ctx, 'test/js/object').then((config) => {
return postcss(config.plugins)
.process(fixture('js/object', 'index.css'), config.options)
.then((result) => {
expect(result.css).toEqual(expected('js/object', 'index.css'))
})
})
})

test('postcss.config.js - {Object} - Process SSS', () => {
const ctx = {
from: './test/js/object/fixtures/index.sss',
parser: true,
syntax: false
}

return postcssrc(ctx, 'test/js/object').then((config) => {
return postcss(config.plugins)
.process(fixture('js/object', 'index.sss'), config.options)
.then((result) => {
expect(result.css).toEqual(expected('js/object', 'index.sss'))
})
})
})

test('postcss.config.js - {Array} - Load Config', () => {
const ctx = {
parser: true,
syntax: true
}

return postcssrc(ctx, 'test/js/array').then((config) => {
expect(config.options.parser).toEqual(require('sugarss'))
expect(config.options.syntax).toEqual(require('sugarss'))
expect(config.options.map).toEqual(false)
expect(config.options.from).toEqual('./test/js/array/fixtures/index.css')
expect(config.options.to).toEqual('./test/js/array/expect/index.css')

expect(config.plugins.length).toEqual(2)
expect(typeof config.plugins[0]).toBe('function')
expect(typeof config.plugins[1]).toBe('function')

expect(config.file)
.toEqual(path.resolve('test/js/array', 'postcss.config.js'))
})
})

test('postcss.config.js - {Array} - Process CSS', () => {
const ctx = {
parser: false,
syntax: false
}

return postcssrc(ctx, 'test/js/array').then((config) => {
return postcss(config.plugins)
.process(fixture('js/array', 'index.css'), config.options)
.then((result) => {
expect(result.css).toEqual(expected('js/array', 'index.css'))
})
})
})

test('postcss.config.js - {Array} - Process SSS', () => {
const ctx = {
from: './test/js/array/fixtures/index.sss',
parser: true,
syntax: false
}

return postcssrc(ctx, 'test/js/array').then((config) => {
return postcss(config.plugins)
.process(fixture('js/array', 'index.sss'), config.options)
.then((result) => {
expect(result.css).toEqual(expected('js/array', 'index.sss'))
})
})
})
63 changes: 0 additions & 63 deletions test/js/array/index.js

This file was deleted.

4 changes: 1 addition & 3 deletions test/js/array/postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
module.exports = function (ctx) {
return {
parser: ctx.parser ? 'sugarss' : false,
syntax: 'postcss-scss',
syntax: ctx.syntax ? 'sugarss' : false,
map: ctx.map ? 'inline' : false,
from: './test/js/array/fixtures/index.css',
to: './test/js/array/expect/index.css',
plugins: [
require('postcss-import')(),
require('postcss-nested')(),
require('postcss-sprites')(),
require('postcss-cssnext')(),
ctx.env === 'production' ? require('cssnano')() : false
]
}
Expand Down
63 changes: 0 additions & 63 deletions test/js/object/index.js

This file was deleted.

4 changes: 1 addition & 3 deletions test/js/object/postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
module.exports = function (ctx) {
return {
parser: ctx.parser ? 'sugarss' : false,
syntax: 'postcss-scss',
syntax: ctx.syntax ? 'sugarss' : false,
map: ctx.map ? 'inline' : false,
from: './test/js/object/fixtures/index.css',
to: './test/js/object/expect/index.css',
plugins: {
'postcss-import': {},
'postcss-nested': {},
'postcss-sprites': {},
'postcss-cssnext': {},
'cssnano': ctx.env === 'production' ? {} : false
}
}
Expand Down
55 changes: 55 additions & 0 deletions test/pkg.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
'use strict'

const path = require('path')

const postcss = require('postcss')
const postcssrc = require('../src/index.js')

const { fixture, expected } = require('./utils.js')

test('package.json - {Object} - Load Config', () => {
return postcssrc({}, 'test/pkg').then((config) => {
expect(config.options.parser).toEqual(require('sugarss'))
expect(config.options.syntax).toEqual(require('sugarss'))
expect(config.options.map).toEqual(false)
expect(config.options.from).toEqual('./test/pkg/fixtures/index.css')
expect(config.options.to).toEqual('./test/pkg/expect/index.css')

expect(config.plugins.length).toEqual(2)
expect(typeof config.plugins[0]).toBe('function')
expect(typeof config.plugins[1]).toBe('function')

expect(config.file)
.toEqual(path.resolve('test/pkg', 'package.json'))
})
})

test('package.json - {Object} - Process CSS', () => {
const ctx = {
parser: false,
syntax: false
}

return postcssrc(ctx, 'test/pkg').then((config) => {
return postcss(config.plugins)
.process(fixture('pkg', 'index.css'), config.options)
.then((result) => {
expect(result.css).toEqual(expected('pkg', 'index.css'))
})
})
})

test('package.json - {Object} - Process SSS', () => {
const ctx = {
from: './test/pkg/fixtures/index.sss',
syntax: false
}

return postcssrc(ctx, 'test/pkg').then((config) => {
return postcss(config.plugins)
.process(fixture('pkg', 'index.sss'), config.options)
.then((result) => {
expect(result.css).toEqual(expected('pkg', 'index.sss'))
})
})
})

0 comments on commit e042a6f

Please sign in to comment.