Skip to content

Commit 7e7b6d9

Browse files
committed
Fix conflict
2 parents 5066a1e + 46f1f97 commit 7e7b6d9

File tree

152 files changed

+45683
-39284
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+45683
-39284
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/lib
22
/docs
33
/__tests__/fixtures/cli-utils.js
4-
defaultConfig.stub.js
4+
/stubs/*

.eslintrc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
"jest": true
44
},
55
"parserOptions": {
6-
"ecmaVersion": 6,
7-
"sourceType": "module",
8-
"ecmaFeatures": {
9-
"experimentalObjectRestSpread": true
10-
}
6+
"ecmaVersion": 2018,
7+
"sourceType": "module"
118
},
129
"extends": ["eslint-config-postcss", "prettier"],
1310
"plugins": ["prettier"],

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/node_modules
22
/lib
33
/example
4+
index.html
5+
package-lock.json
46
yarn-error.log

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/__tests__/
22
/jest/
33
/src/
4+
index.html
45
yarn-error.log

__tests__/applyAtRule.test.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import postcss from 'postcss'
22
import substituteClassApplyAtRules from '../src/lib/substituteClassApplyAtRules'
33
import processPlugins from '../src/util/processPlugins'
4-
import defaultPlugins from '../src/defaultPlugins'
5-
import defaultConfig from '../defaultConfig.stub.js'
4+
import resolveConfig from '../src/util/resolveConfig'
5+
import corePlugins from '../src/corePlugins'
6+
import defaultConfig from '../stubs/defaultConfig.stub.js'
67

7-
const { utilities: defaultUtilities } = processPlugins(defaultPlugins(defaultConfig), defaultConfig)
8+
const resolvedDefaultConfig = resolveConfig([defaultConfig])
89

9-
function run(input, config = defaultConfig, utilities = defaultUtilities) {
10+
const { utilities: defaultUtilities } = processPlugins(
11+
corePlugins(resolvedDefaultConfig),
12+
resolvedDefaultConfig
13+
)
14+
15+
function run(input, config = resolvedDefaultConfig, utilities = defaultUtilities) {
1016
return postcss([substituteClassApplyAtRules(config, utilities)]).process(input, {
1117
from: undefined,
1218
})
@@ -200,20 +206,17 @@ test('you can apply utility classes without using the given prefix', () => {
200206
.foo { margin-top: 1rem; margin-bottom: 1rem; }
201207
`
202208

203-
const config = {
204-
...defaultConfig,
205-
options: {
206-
...defaultConfig.options,
209+
const config = resolveConfig([
210+
{
211+
...defaultConfig,
207212
prefix: 'tw-',
208213
},
209-
}
214+
])
210215

211-
return run(input, config, processPlugins(defaultPlugins(defaultConfig), config).utilities).then(
212-
result => {
213-
expect(result.css).toEqual(expected)
214-
expect(result.warnings().length).toBe(0)
215-
}
216-
)
216+
return run(input, config, processPlugins(corePlugins(config), config).utilities).then(result => {
217+
expect(result.css).toEqual(expected)
218+
expect(result.warnings().length).toBe(0)
219+
})
217220
})
218221

219222
test('you can apply utility classes without using the given prefix when using a function for the prefix', () => {
@@ -225,20 +228,17 @@ test('you can apply utility classes without using the given prefix when using a
225228
.foo { margin-top: 1rem; margin-bottom: 1rem; }
226229
`
227230

228-
const config = {
229-
...defaultConfig,
230-
options: {
231-
...defaultConfig.options,
231+
const config = resolveConfig([
232+
{
233+
...defaultConfig,
232234
prefix: () => {
233235
return 'tw-'
234236
},
235237
},
236-
}
238+
])
237239

238-
return run(input, config, processPlugins(defaultPlugins(defaultConfig), config).utilities).then(
239-
result => {
240-
expect(result.css).toEqual(expected)
241-
expect(result.warnings().length).toBe(0)
242-
}
243-
)
240+
return run(input, config, processPlugins(corePlugins(config), config).utilities).then(result => {
241+
expect(result.css).toEqual(expected)
242+
expect(result.warnings().length).toBe(0)
243+
})
244244
})

__tests__/cli.test.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,43 @@
11
import path from 'path'
22

33
import cli from '../src/cli/main'
4-
import * as constants from '../src/cli/constants'
4+
import * as constants from '../src/constants'
55
import * as utils from '../src/cli/utils'
6+
import runInTempDirectory from '../jest/runInTempDirectory'
67

78
describe('cli', () => {
89
const inputCssPath = path.resolve(__dirname, 'fixtures/tailwind-input.css')
910
const customConfigPath = path.resolve(__dirname, 'fixtures/custom-config.js')
11+
const defaultConfigFixture = utils.readFile(constants.defaultConfigStubFile)
12+
const simpleConfigFixture = utils.readFile(constants.simpleConfigStubFile)
1013

1114
beforeEach(() => {
1215
console.log = jest.fn()
1316
process.stdout.write = jest.fn()
14-
utils.writeFile = jest.fn()
1517
})
1618

1719
describe('init', () => {
1820
it('creates a Tailwind config file', () => {
19-
return cli(['init']).then(() => {
20-
expect(utils.writeFile.mock.calls[0][0]).toEqual(constants.defaultConfigFile)
21-
expect(utils.writeFile.mock.calls[0][1]).toContain('defaultConfig')
21+
return runInTempDirectory(() => {
22+
return cli(['init']).then(() => {
23+
expect(utils.readFile(constants.defaultConfigFile)).toEqual(simpleConfigFixture)
24+
})
2225
})
2326
})
2427

25-
it('creates a Tailwind config file in a custom location', () => {
26-
return cli(['init', 'custom.js']).then(() => {
27-
expect(utils.writeFile.mock.calls[0][0]).toEqual('custom.js')
28-
expect(utils.writeFile.mock.calls[0][1]).toContain('defaultConfig')
28+
it('creates a full Tailwind config file', () => {
29+
return runInTempDirectory(() => {
30+
return cli(['init', '--full']).then(() => {
31+
expect(utils.readFile(constants.defaultConfigFile)).toEqual(defaultConfigFixture)
32+
})
2933
})
3034
})
3135

32-
it('creates a Tailwind config file without comments', () => {
33-
return cli(['init', '--no-comments']).then(() => {
34-
expect(utils.writeFile.mock.calls[0][1]).not.toContain('/**')
35-
expect(utils.writeFile.mock.calls[0][1]).toContain('//')
36+
it('creates a Tailwind config file in a custom location', () => {
37+
return runInTempDirectory(() => {
38+
return cli(['init', 'custom.js']).then(() => {
39+
expect(utils.exists('custom.js')).toEqual(true)
40+
})
3641
})
3742
})
3843
})
@@ -51,9 +56,10 @@ describe('cli', () => {
5156
})
5257

5358
it('creates compiled CSS file', () => {
54-
return cli(['build', inputCssPath, '--output', 'output.css']).then(() => {
55-
expect(utils.writeFile.mock.calls[0][0]).toEqual('output.css')
56-
expect(utils.writeFile.mock.calls[0][1]).toContain('.example')
59+
return runInTempDirectory(() => {
60+
return cli(['build', inputCssPath, '--output', 'output.css']).then(() => {
61+
expect(utils.readFile('output.css')).toContain('.example')
62+
})
5763
})
5864
})
5965

__tests__/cli.utils.test.js

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import path from 'path'
2-
31
import * as utils from '../src/cli/utils'
42

53
describe('cli utils', () => {
6-
const fixture = utils.readFile(path.resolve(__dirname, 'fixtures/cli-utils.js'))
7-
84
describe('parseCliParams', () => {
95
it('parses CLI parameters', () => {
106
const result = utils.parseCliParams(['a', 'b', '-c', 'd'])
@@ -61,52 +57,17 @@ describe('cli utils', () => {
6157
})
6258
})
6359

64-
describe('stripBlockComments', () => {
65-
it('does not strip code', () => {
66-
const result = utils.stripBlockComments(fixture)
67-
68-
expect(result).toEqual(expect.stringContaining('__code_no_comment__'))
69-
expect(result).toEqual(expect.stringContaining('__code_comment_line__'))
70-
expect(result).toEqual(expect.stringContaining('__code_comment_block__'))
71-
expect(result).toEqual(expect.stringContaining('__code_comment_line_important__'))
72-
expect(result).toEqual(expect.stringContaining('__code_comment_block_important__'))
73-
})
74-
75-
it('strips block comments', () => {
76-
const result = utils.stripBlockComments(fixture)
77-
78-
expect(result).not.toEqual(expect.stringContaining('__comment_block__'))
79-
expect(result).not.toEqual(expect.stringContaining('__comment_block_multiline__'))
80-
expect(result).not.toEqual(expect.stringContaining('__comment_block_code__'))
81-
})
82-
83-
it('strips docblock comments', () => {
84-
const result = utils.stripBlockComments(fixture)
85-
86-
expect(result).not.toEqual(expect.stringContaining('__comment_docblock__'))
87-
})
88-
89-
it('does not strip line comments', () => {
90-
const result = utils.stripBlockComments(fixture)
91-
92-
expect(result).toEqual(expect.stringContaining('__comment_line__'))
93-
expect(result).toEqual(expect.stringContaining('__comment_line_important__'))
94-
expect(result).toEqual(expect.stringContaining('__comment_line_code__'))
95-
expect(result).toEqual(expect.stringContaining('__comment_line_important_code__'))
96-
})
97-
98-
it('does not strip important block comments', () => {
99-
const result = utils.stripBlockComments(fixture)
60+
describe('getSimplePath', () => {
61+
it('strips leading ./', () => {
62+
const result = utils.getSimplePath('./test')
10063

101-
expect(result).toEqual(expect.stringContaining('__comment_block_important__'))
102-
expect(result).toEqual(expect.stringContaining('__comment_block_multiline_important__'))
103-
expect(result).toEqual(expect.stringContaining('__comment_block_important_code__'))
64+
expect(result).toEqual('test')
10465
})
10566

106-
it('does not strip important docblock comments', () => {
107-
const result = utils.stripBlockComments(fixture)
67+
it('returns unchanged path if it does not begin with ./', () => {
68+
const result = utils.getSimplePath('../test')
10869

109-
expect(result).toEqual(expect.stringContaining('__comment_docblock_important__'))
70+
expect(result).toEqual('../test')
11071
})
11172
})
11273
})

__tests__/configurePlugins.test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import configurePlugins from '../src/util/configurePlugins'
2+
3+
test('setting a plugin to false removes it', () => {
4+
const plugins = {
5+
fontSize: () => 'fontSize',
6+
display: () => 'display',
7+
backgroundPosition: () => 'backgroundPosition',
8+
}
9+
10+
const configuredPlugins = configurePlugins(
11+
{
12+
display: false,
13+
},
14+
plugins
15+
)
16+
17+
expect(configuredPlugins).toEqual(['fontSize', 'backgroundPosition'])
18+
})
19+
20+
test('passing only false removes all plugins', () => {
21+
const plugins = {
22+
fontSize: () => 'fontSize',
23+
display: () => 'display',
24+
backgroundPosition: () => 'backgroundPosition',
25+
}
26+
27+
const configuredPlugins = configurePlugins(false, plugins)
28+
29+
expect(configuredPlugins).toEqual([])
30+
})
31+
32+
test('passing an array whitelists plugins', () => {
33+
const plugins = {
34+
fontSize: () => 'fontSize',
35+
display: () => 'display',
36+
backgroundPosition: () => 'backgroundPosition',
37+
}
38+
39+
const configuredPlugins = configurePlugins(['display'], plugins)
40+
41+
expect(configuredPlugins).toEqual(['display'])
42+
})

0 commit comments

Comments
 (0)