Skip to content

Commit

Permalink
Enable babel for src and tests
Browse files Browse the repository at this point in the history
We still have to use it seriously now

Ref MoOx#101
  • Loading branch information
MoOx committed Jun 5, 2015
1 parent 87663dd commit 91177c8
Show file tree
Hide file tree
Showing 90 changed files with 264 additions and 115 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
node_modules

# standalone build
dist
docs/dist

# fixtures
test/**/*.actual.css
7 changes: 7 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# no need for compiled tests
dist/__tests__

# no need for website sources on npm
docs/dist
docs/scripts
docs/src
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ $ git checkout -b fix.bug423

### Add a feature

1. Add test files (input + expected output) in [`test/fixtures/features`](test/features)
- If the feature can affect some others, update [`test/fixtures/cases/example.css`](test/cases/example.css) to test integration with other features
1. Add test files (input + expected output) in [`src/__tests__/fixtures/features`](src/__tests__/features)
- 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
- Run test, & check tests are broken (otherwise feature is useless)
- Choose a pretty simple and clear name (that match the specs)
- Add the feature in the [README features list](#features) (title, link to spec, link of the plugin, short desc)
Expand Down
22 changes: 10 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
"bugs": {
"url": "https://github.com/cssnext/cssnext/issues"
},
"files": [
"CHANGELOG.md",
"LICENSE",
"bin",
"index.js"
],
"main": "dist/index.js",
"bin": {
"cssnext": "dist/bin.js"
},
"dependencies": {
"autoprefixer-core": "^5.0.0",
"caniuse-api": "^1.3.1",
Expand Down Expand Up @@ -110,18 +108,18 @@
"webpack-nano-logs": "^1.0.0"
},
"scripts": {
"standalone": "browserify --standalone cssnext index.js -o dist/cssnext.js",
"babelify": "babel src --out-dir dist",
"prepublish": "npm run babelify",
"standalone": "browserify --standalone cssnext dist/index.js -o dist/cssnext.js",
"#lint": "even if there is a .eslintignore symlink, we use an explicit command because windows don't like unix symlink",
"lint": "eslint --ignore-path .gitignore .",
"tape": "tape test/*.js",
"test": "npm run lint && npm run standalone && npm run tape",
"#tape": "to avoid really slow tests, we run babel once & run tests on the result",
"tape": "tape 'dist/__tests__/*.js'",
"test": "npm run lint && npm run standalone && npm run babelify && npm run tape",
"docs-build": "babel-node docs/scripts/build",
"docs-start": "npm run docs-build -- --dev-server --open",
"docs-test": "npm run docs-build -- --production",
"_docs-deploy": "GIT_DEPLOY_DIR=docs/dist ./docs/scripts/deploy-to-gh-pages.sh -v",
"docs-deploy": "npm run docs-test && npm run _docs-deploy"
},
"bin": {
"cssnext": "bin/cssnext.js"
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var t = require("microtime")
var assign = require("object-assign")

var input = require("fs").readFileSync(
"./test/benchmarks.css",
"./src/__tests__/benchmarks.css",
{encoding: "utf8"}
)

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

// test each features
var keys = Object.keys(cssnext.features)
Expand Down
File renamed without changes.
150 changes: 83 additions & 67 deletions test/cli.js → src/__tests__/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ var cssnext = require("..")
var input = utils.readFixture("cli")
var output = utils.readFixture("cli.expected")

var cssnextBin = "node bin/cssnext" // node bin is used to help for windows
// node bin is used to help for windows
var cssnextBin = "node dist/bin"

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

exec(
cssnextBin + " test/fixtures/cli.css test/fixtures/cli.output--io.css",
cssnextBin +
" src/__tests__/fixtures/cli.css" +
" src/__tests__/fixtures/cli.output--io.css",
function(err) {
if (err) {
throw err
Expand All @@ -32,7 +35,7 @@ test("cli", function(t) {
)
planned += 1

exec(cssnextBin + " test/fixtures/cli.css", function(err, stdout) {
exec(cssnextBin + " src/__tests__/fixtures/cli.css", function(err, stdout) {
if (err) {
throw err
}
Expand All @@ -54,7 +57,7 @@ test("cli", function(t) {
planned += 1

exec(
cssnextBin + " test/fixtures/cli.dont-exist.css",
cssnextBin + " src/__tests__/fixtures/cli.dont-exist.css",
function(err, stdout, stderr) {
t.ok(
err && err.code === 1,
Expand All @@ -69,7 +72,7 @@ test("cli", function(t) {
planned += 2

exec(
cssnextBin + " test/fixtures/cli.error.css",
cssnextBin + " src/__tests__/fixtures/cli.error.css",
function(err, stdout, stderr) {
t.ok(err && err.code === 2, "should throw an error")
t.ok(
Expand All @@ -86,7 +89,9 @@ test("cli", function(t) {
planned += 3

exec(
cssnextBin + " --config test/fixtures/config.json test/fixtures/config.css",
cssnextBin +
" --config src/__tests__/fixtures/config.json" +
" src/__tests__/fixtures/config.css",
function(err, stdout) {
if (err) {
throw err
Expand Down Expand Up @@ -114,7 +119,8 @@ test("cli", function(t) {

exec(
cssnextBin +
" --verbose test/fixtures/cli.css test/fixtures/cli.output--verbose.css"
" --verbose src/__tests__/fixtures/cli.css" +
" src/__tests__/fixtures/cli.output--verbose.css"
,
function(err, stdout) {
if (err) {
Expand All @@ -127,7 +133,7 @@ test("cli", function(t) {
planned += 1

exec(
cssnextBin + " --no-import test/fixtures/import.css",
cssnextBin + " --no-import src/__tests__/fixtures/import.css",
function(err, stdout) {
if (err) {
throw err
Expand All @@ -141,45 +147,51 @@ test("cli", function(t) {
planned += 1

exec(
cssnextBin + " --no-url test/fixtures/url.css", {cwd: process.cwd()},
cssnextBin + " --no-url src/__tests__/fixtures/url.css",
{cwd: process.cwd()},
function(err, stdout) {
if (err) {
throw err
if (err) {
throw err
}
t.equal(
stdout,
utils.readFixture("url/dep"),
"should not adjust url on --no-url"
)
}
t.equal(
stdout,
utils.readFixture("url/dep"),
"should not adjust url on --no-url"
)
})
)
planned += 1

exec(
cssnextBin + " --compress test/fixtures/compress.css",
cssnextBin + " --compress src/__tests__/fixtures/compress.css",
function(err, stdout) {
if (err) {
throw err
if (err) {
throw err
}
t.equal(
stdout.trim(),
utils.readFixture("compress.default.expected").trim(),
"should compress on --compress"
)
}
t.equal(
stdout.trim(),
utils.readFixture("compress.default.expected").trim(),
"should compress on --compress"
)
})
)
planned += 1

exec(
cssnextBin + " --sourcemap test/fixtures/sourcemap.css",
cssnextBin + " --sourcemap src/__tests__/fixtures/sourcemap.css",
function(err, stdout) {
if (err) {
throw err
if (err) {
throw err
}
t.ok(
stdout
.indexOf("/*# sourceMappingURL=data:application/json;base64,")
> -1
,
"should add sourcemap on --sourcemap"
)
}
t.equal(
stdout,
utils.readFixture("sourcemap.expected").trim(),
"should add sourcemap on --sourcemap"
)
})
)
planned += 1

var toSpace = require("to-space-case")
Expand All @@ -192,50 +204,54 @@ test("cli", function(t) {
var slug = toSlug(feature)
var featureOutput = utils.readFixture("features/" + slug)
exec(
cssnextBin + " " + no + " test/fixtures/features/" + slug + ".css",
cssnextBin + " " + no +
" src/__tests__/fixtures/features/" + slug + ".css",
function(err, stdout) {
if (err) {
throw err
if (err) {
throw err
}
t.equal(
stdout,
featureOutput,
"should not modify input of '" + toSpace(feature) +
"' fixture if all features are disabled"
)
}
t.equal(
stdout,
featureOutput,
"should not modify input of '" + toSpace(feature) +
"' fixture if all features are disabled"
)
})
)
})
planned += features.length

exec(
cssnextBin + " --watch",
function(err, stdout, stderr) {
t.ok(err && err.code === 3,
"should return an error when <input> or <output> are missing when " +
"`--watch` option passed"
)
t.ok(
utils.contains(stderr, "--watch option need"),
"should show an explanation when <input> or <output> are missing when " +
"`--watch` option passed"
)
})
t.ok(err && err.code === 3,
"should return an error when <input> or <output> are missing when " +
"`--watch` option passed"
)
t.ok(
utils.contains(stderr, "--watch option need"),
"should show an explanation when <input> or <output> are missing when" +
" `--watch` option passed"
)
}
)
planned += 2

exec(
cssnextBin + " --watch test/fixtures/cli.css",
cssnextBin + " --watch src/__tests__/fixtures/cli.css",
function(err, stdout, stderr) {
t.ok(
err && err.code === 3,
"should return an error when <output> is missing when `--watch` option " +
"passed"
)
t.ok(
utils.contains(stderr, "--watch option need"),
"should show an explanation when <output> is missing when `--watch` " +
"option passed"
)
})
t.ok(
err && err.code === 3,
"should return an error when <output> is missing when `--watch`" +
"option passed"
)
t.ok(
utils.contains(stderr, "--watch option need"),
"should show an explanation when <output> is missing when `--watch` " +
"option passed"
)
}
)
planned += 2

t.plan(planned)
Expand Down
24 changes: 15 additions & 9 deletions test/cli.watcher.js → src/__tests__/cli.watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ var utils = require("./utils")
// I don't success to call the kill() process from node and both Travis CI and
// Appveyor so we avoid this test on this environnements
if (!(process.env.TRAVIS || process.env.APPVEYOR)) {
var cssnextBin = "node bin/cssnext" // node bin is used to help for windows
// node bin is used to help for windows
var cssnextBin = "node dist/bin"

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

var watchProcess = exec(
cssnextBin + " --watch test/fixtures/cli.error.css test/fixtures/" +
"cli.output--watch.css",
cssnextBin +
" --watch src/__tests__/fixtures/cli.error.css" +
" src/__tests__/fixtures/cli.output--watch.css",
function(err) {
t.ok(
err && err.signal === "SIGTERM",
Expand All @@ -46,14 +48,14 @@ if (!(process.env.TRAVIS || process.env.APPVEYOR)) {
planned += 2

// watch/import tests
var watchOut = "test/fixtures/cli.output--watch-import.css"
var watchOut = "src/__tests__/fixtures/cli.output--watch-import.css"

var watchImportProcess = spawn(
"node",
[
"bin/cssnext",
"dist/bin",
"--watch",
"test/fixtures/cli.watch-import.css",
"src/__tests__/fixtures/cli.watch-import.css",
watchOut,
],
{stdio: "inherit"}
Expand All @@ -66,7 +68,7 @@ if (!(process.env.TRAVIS || process.env.APPVEYOR)) {
// trigger a change in cli.import.css to add a new watched file
// cli.import2.css
fs.writeFileSync(
"test/fixtures/cli.watch-import.css",
"src/__tests__/fixtures/cli.watch-import.css",
"/**/ @import 'cli.watch-import-import.css';"
)

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

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

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

// trigger a change in previously imported file
var now = (new Date()).getTime()
fs.utimesSync("test/fixtures/cli.watch-import-import.css", now, now)
fs.utimesSync(
"src/__tests__/fixtures/cli.watch-import-import.css",
now,
now
)

// not sure why but it's better with the statSync on the watched file
// in this delayed call
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 91177c8

Please sign in to comment.