Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

Commit 91177c8

Browse files
committed
Enable babel for src and tests
We still have to use it seriously now Ref #101
1 parent 87663dd commit 91177c8

File tree

90 files changed

+264
-115
lines changed

Some content is hidden

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

90 files changed

+264
-115
lines changed

.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
node_modules
22

3-
# standalone build
43
dist
54
docs/dist
6-
7-
# fixtures
8-
test/**/*.actual.css

.npmignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# no need for compiled tests
2+
dist/__tests__
3+
4+
# no need for website sources on npm
5+
docs/dist
6+
docs/scripts
7+
docs/src

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ $ git checkout -b fix.bug423
1616

1717
### Add a feature
1818

19-
1. Add test files (input + expected output) in [`test/fixtures/features`](test/features)
20-
- If the feature can affect some others, update [`test/fixtures/cases/example.css`](test/cases/example.css) to test integration with other features
19+
1. Add test files (input + expected output) in [`src/__tests__/fixtures/features`](src/__tests__/features)
20+
- If the feature can affect some others, update [`src/__tests__/fixtures/cases/example.css`](src/__tests__/cases/example.css) to test integration with other features
2121
- Run test, & check tests are broken (otherwise feature is useless)
2222
- Choose a pretty simple and clear name (that match the specs)
2323
- Add the feature in the [README features list](#features) (title, link to spec, link of the plugin, short desc)

package.json

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@
2020
"bugs": {
2121
"url": "https://github.com/cssnext/cssnext/issues"
2222
},
23-
"files": [
24-
"CHANGELOG.md",
25-
"LICENSE",
26-
"bin",
27-
"index.js"
28-
],
23+
"main": "dist/index.js",
24+
"bin": {
25+
"cssnext": "dist/bin.js"
26+
},
2927
"dependencies": {
3028
"autoprefixer-core": "^5.0.0",
3129
"caniuse-api": "^1.3.1",
@@ -110,18 +108,18 @@
110108
"webpack-nano-logs": "^1.0.0"
111109
},
112110
"scripts": {
113-
"standalone": "browserify --standalone cssnext index.js -o dist/cssnext.js",
111+
"babelify": "babel src --out-dir dist",
112+
"prepublish": "npm run babelify",
113+
"standalone": "browserify --standalone cssnext dist/index.js -o dist/cssnext.js",
114114
"#lint": "even if there is a .eslintignore symlink, we use an explicit command because windows don't like unix symlink",
115115
"lint": "eslint --ignore-path .gitignore .",
116-
"tape": "tape test/*.js",
117-
"test": "npm run lint && npm run standalone && npm run tape",
116+
"#tape": "to avoid really slow tests, we run babel once & run tests on the result",
117+
"tape": "tape 'dist/__tests__/*.js'",
118+
"test": "npm run lint && npm run standalone && npm run babelify && npm run tape",
118119
"docs-build": "babel-node docs/scripts/build",
119120
"docs-start": "npm run docs-build -- --dev-server --open",
120121
"docs-test": "npm run docs-build -- --production",
121122
"_docs-deploy": "GIT_DEPLOY_DIR=docs/dist ./docs/scripts/deploy-to-gh-pages.sh -v",
122123
"docs-deploy": "npm run docs-test && npm run _docs-deploy"
123-
},
124-
"bin": {
125-
"cssnext": "bin/cssnext.js"
126124
}
127125
}
File renamed without changes.
File renamed without changes.

test/benchmarks/index.js renamed to src/__tests__/benchmarks/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var t = require("microtime")
33
var assign = require("object-assign")
44

55
var input = require("fs").readFileSync(
6-
"./test/benchmarks.css",
6+
"./src/__tests__/benchmarks.css",
77
{encoding: "utf8"}
88
)
99

@@ -12,7 +12,7 @@ for (var i = 0; i <= 10; i++) {
1212
input += input
1313
}
1414
// check the real input
15-
// require("fs").writeFileSync("./test/fixtures/bench.css", input)
15+
// require("fs").writeFileSync("./src/__tests__/fixtures/bench.css", input)
1616

1717
// test each features
1818
var keys = Object.keys(cssnext.features)
File renamed without changes.

test/cli.js renamed to src/__tests__/cli.js

Lines changed: 83 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ var cssnext = require("..")
1414
var input = utils.readFixture("cli")
1515
var output = utils.readFixture("cli.expected")
1616

17-
var cssnextBin = "node bin/cssnext" // node bin is used to help for windows
17+
// node bin is used to help for windows
18+
var cssnextBin = "node dist/bin"
1819

1920
test("cli", function(t) {
2021
var planned = 0
2122

2223
exec(
23-
cssnextBin + " test/fixtures/cli.css test/fixtures/cli.output--io.css",
24+
cssnextBin +
25+
" src/__tests__/fixtures/cli.css" +
26+
" src/__tests__/fixtures/cli.output--io.css",
2427
function(err) {
2528
if (err) {
2629
throw err
@@ -32,7 +35,7 @@ test("cli", function(t) {
3235
)
3336
planned += 1
3437

35-
exec(cssnextBin + " test/fixtures/cli.css", function(err, stdout) {
38+
exec(cssnextBin + " src/__tests__/fixtures/cli.css", function(err, stdout) {
3639
if (err) {
3740
throw err
3841
}
@@ -54,7 +57,7 @@ test("cli", function(t) {
5457
planned += 1
5558

5659
exec(
57-
cssnextBin + " test/fixtures/cli.dont-exist.css",
60+
cssnextBin + " src/__tests__/fixtures/cli.dont-exist.css",
5861
function(err, stdout, stderr) {
5962
t.ok(
6063
err && err.code === 1,
@@ -69,7 +72,7 @@ test("cli", function(t) {
6972
planned += 2
7073

7174
exec(
72-
cssnextBin + " test/fixtures/cli.error.css",
75+
cssnextBin + " src/__tests__/fixtures/cli.error.css",
7376
function(err, stdout, stderr) {
7477
t.ok(err && err.code === 2, "should throw an error")
7578
t.ok(
@@ -86,7 +89,9 @@ test("cli", function(t) {
8689
planned += 3
8790

8891
exec(
89-
cssnextBin + " --config test/fixtures/config.json test/fixtures/config.css",
92+
cssnextBin +
93+
" --config src/__tests__/fixtures/config.json" +
94+
" src/__tests__/fixtures/config.css",
9095
function(err, stdout) {
9196
if (err) {
9297
throw err
@@ -114,7 +119,8 @@ test("cli", function(t) {
114119

115120
exec(
116121
cssnextBin +
117-
" --verbose test/fixtures/cli.css test/fixtures/cli.output--verbose.css"
122+
" --verbose src/__tests__/fixtures/cli.css" +
123+
" src/__tests__/fixtures/cli.output--verbose.css"
118124
,
119125
function(err, stdout) {
120126
if (err) {
@@ -127,7 +133,7 @@ test("cli", function(t) {
127133
planned += 1
128134

129135
exec(
130-
cssnextBin + " --no-import test/fixtures/import.css",
136+
cssnextBin + " --no-import src/__tests__/fixtures/import.css",
131137
function(err, stdout) {
132138
if (err) {
133139
throw err
@@ -141,45 +147,51 @@ test("cli", function(t) {
141147
planned += 1
142148

143149
exec(
144-
cssnextBin + " --no-url test/fixtures/url.css", {cwd: process.cwd()},
150+
cssnextBin + " --no-url src/__tests__/fixtures/url.css",
151+
{cwd: process.cwd()},
145152
function(err, stdout) {
146-
if (err) {
147-
throw err
153+
if (err) {
154+
throw err
155+
}
156+
t.equal(
157+
stdout,
158+
utils.readFixture("url/dep"),
159+
"should not adjust url on --no-url"
160+
)
148161
}
149-
t.equal(
150-
stdout,
151-
utils.readFixture("url/dep"),
152-
"should not adjust url on --no-url"
153-
)
154-
})
162+
)
155163
planned += 1
156164

157165
exec(
158-
cssnextBin + " --compress test/fixtures/compress.css",
166+
cssnextBin + " --compress src/__tests__/fixtures/compress.css",
159167
function(err, stdout) {
160-
if (err) {
161-
throw err
168+
if (err) {
169+
throw err
170+
}
171+
t.equal(
172+
stdout.trim(),
173+
utils.readFixture("compress.default.expected").trim(),
174+
"should compress on --compress"
175+
)
162176
}
163-
t.equal(
164-
stdout.trim(),
165-
utils.readFixture("compress.default.expected").trim(),
166-
"should compress on --compress"
167-
)
168-
})
177+
)
169178
planned += 1
170179

171180
exec(
172-
cssnextBin + " --sourcemap test/fixtures/sourcemap.css",
181+
cssnextBin + " --sourcemap src/__tests__/fixtures/sourcemap.css",
173182
function(err, stdout) {
174-
if (err) {
175-
throw err
183+
if (err) {
184+
throw err
185+
}
186+
t.ok(
187+
stdout
188+
.indexOf("/*# sourceMappingURL=data:application/json;base64,")
189+
> -1
190+
,
191+
"should add sourcemap on --sourcemap"
192+
)
176193
}
177-
t.equal(
178-
stdout,
179-
utils.readFixture("sourcemap.expected").trim(),
180-
"should add sourcemap on --sourcemap"
181-
)
182-
})
194+
)
183195
planned += 1
184196

185197
var toSpace = require("to-space-case")
@@ -192,50 +204,54 @@ test("cli", function(t) {
192204
var slug = toSlug(feature)
193205
var featureOutput = utils.readFixture("features/" + slug)
194206
exec(
195-
cssnextBin + " " + no + " test/fixtures/features/" + slug + ".css",
207+
cssnextBin + " " + no +
208+
" src/__tests__/fixtures/features/" + slug + ".css",
196209
function(err, stdout) {
197-
if (err) {
198-
throw err
210+
if (err) {
211+
throw err
212+
}
213+
t.equal(
214+
stdout,
215+
featureOutput,
216+
"should not modify input of '" + toSpace(feature) +
217+
"' fixture if all features are disabled"
218+
)
199219
}
200-
t.equal(
201-
stdout,
202-
featureOutput,
203-
"should not modify input of '" + toSpace(feature) +
204-
"' fixture if all features are disabled"
205-
)
206-
})
220+
)
207221
})
208222
planned += features.length
209223

210224
exec(
211225
cssnextBin + " --watch",
212226
function(err, stdout, stderr) {
213-
t.ok(err && err.code === 3,
214-
"should return an error when <input> or <output> are missing when " +
215-
"`--watch` option passed"
216-
)
217-
t.ok(
218-
utils.contains(stderr, "--watch option need"),
219-
"should show an explanation when <input> or <output> are missing when " +
220-
"`--watch` option passed"
221-
)
222-
})
227+
t.ok(err && err.code === 3,
228+
"should return an error when <input> or <output> are missing when " +
229+
"`--watch` option passed"
230+
)
231+
t.ok(
232+
utils.contains(stderr, "--watch option need"),
233+
"should show an explanation when <input> or <output> are missing when" +
234+
" `--watch` option passed"
235+
)
236+
}
237+
)
223238
planned += 2
224239

225240
exec(
226-
cssnextBin + " --watch test/fixtures/cli.css",
241+
cssnextBin + " --watch src/__tests__/fixtures/cli.css",
227242
function(err, stdout, stderr) {
228-
t.ok(
229-
err && err.code === 3,
230-
"should return an error when <output> is missing when `--watch` option " +
231-
"passed"
232-
)
233-
t.ok(
234-
utils.contains(stderr, "--watch option need"),
235-
"should show an explanation when <output> is missing when `--watch` " +
236-
"option passed"
237-
)
238-
})
243+
t.ok(
244+
err && err.code === 3,
245+
"should return an error when <output> is missing when `--watch`" +
246+
"option passed"
247+
)
248+
t.ok(
249+
utils.contains(stderr, "--watch option need"),
250+
"should show an explanation when <output> is missing when `--watch` " +
251+
"option passed"
252+
)
253+
}
254+
)
239255
planned += 2
240256

241257
t.plan(planned)

test/cli.watcher.js renamed to src/__tests__/cli.watcher.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ var utils = require("./utils")
1212
// I don't success to call the kill() process from node and both Travis CI and
1313
// Appveyor so we avoid this test on this environnements
1414
if (!(process.env.TRAVIS || process.env.APPVEYOR)) {
15-
var cssnextBin = "node bin/cssnext" // node bin is used to help for windows
15+
// node bin is used to help for windows
16+
var cssnextBin = "node dist/bin"
1617

1718
test("cli/watcher", function(t) {
1819
var planned = 0
1920

2021
var watchProcess = exec(
21-
cssnextBin + " --watch test/fixtures/cli.error.css test/fixtures/" +
22-
"cli.output--watch.css",
22+
cssnextBin +
23+
" --watch src/__tests__/fixtures/cli.error.css" +
24+
" src/__tests__/fixtures/cli.output--watch.css",
2325
function(err) {
2426
t.ok(
2527
err && err.signal === "SIGTERM",
@@ -46,14 +48,14 @@ if (!(process.env.TRAVIS || process.env.APPVEYOR)) {
4648
planned += 2
4749

4850
// watch/import tests
49-
var watchOut = "test/fixtures/cli.output--watch-import.css"
51+
var watchOut = "src/__tests__/fixtures/cli.output--watch-import.css"
5052

5153
var watchImportProcess = spawn(
5254
"node",
5355
[
54-
"bin/cssnext",
56+
"dist/bin",
5557
"--watch",
56-
"test/fixtures/cli.watch-import.css",
58+
"src/__tests__/fixtures/cli.watch-import.css",
5759
watchOut,
5860
],
5961
{stdio: "inherit"}
@@ -66,7 +68,7 @@ if (!(process.env.TRAVIS || process.env.APPVEYOR)) {
6668
// trigger a change in cli.import.css to add a new watched file
6769
// cli.import2.css
6870
fs.writeFileSync(
69-
"test/fixtures/cli.watch-import.css",
71+
"src/__tests__/fixtures/cli.watch-import.css",
7072
"/**/ @import 'cli.watch-import-import.css';"
7173
)
7274

@@ -83,7 +85,7 @@ if (!(process.env.TRAVIS || process.env.APPVEYOR)) {
8385
)
8486

8587
// remove this newly imported file
86-
fs.writeFileSync("test/fixtures/cli.watch-import.css", "/**/")
88+
fs.writeFileSync("src/__tests__/fixtures/cli.watch-import.css", "/**/")
8789

8890
// check the output has been update
8991
setTimeout(function() {
@@ -103,7 +105,11 @@ if (!(process.env.TRAVIS || process.env.APPVEYOR)) {
103105

104106
// trigger a change in previously imported file
105107
var now = (new Date()).getTime()
106-
fs.utimesSync("test/fixtures/cli.watch-import-import.css", now, now)
108+
fs.utimesSync(
109+
"src/__tests__/fixtures/cli.watch-import-import.css",
110+
now,
111+
now
112+
)
107113

108114
// not sure why but it's better with the statSync on the watched file
109115
// in this delayed call

0 commit comments

Comments
 (0)