Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Commit

Permalink
Use ava for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Aug 1, 2016
1 parent 64a3ef0 commit 1bb7c30
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 67 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
index.js
coverage/
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "simenb-base"
"extends": ["simenb-base", "simenb-ava"]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ node_modules/
.idea/
*.log
coverage/
.nyc_output/
38 changes: 22 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@
"text-table": "^0.2.0"
},
"devDependencies": {
"babel-cli": "^6.4.5",
"babel-istanbul": "^0.11.0",
"babel-plugin-add-module-exports": "^0.2.0",
"babel-preset-es2015": "^6.3.13",
"babel-register": "^6.4.3",
"coveralls": "^2.11.6",
"ava": "^0.15.2",
"babel-cli": "^6.11.4",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-es2015": "^6.9.0",
"babel-register": "^6.11.6",
"coveralls": "^2.11.12",
"csslint": "^1.0.2",
"eslint": "^3.1.1",
"eslint": "^3.2.0",
"eslint-config-simenb-ava": "^1.1.1",
"eslint-config-simenb-base": "^2.0.0",
"in-publish": "^2.0.0",
"mocha": "^3.0.0",
"node-version-check": "^2.0.2",
"rimraf": "^2.5.1"
"node-version-check": "^2.1.0",
"nyc": "^7.1.0",
"rimraf": "^2.5.4"
},
"files": [
"index.js"
Expand All @@ -42,15 +43,20 @@
"main": "index.js",
"repository": "SimenB/csslint-stylish",
"scripts": {
"clean": "rimraf coverage/ index.js test-es5.js",
"clean": "rimraf coverage/ .nyc_output/ index.js",
"compile": "babel stylish.js -o index.js",
"compile-test": "babel test.js -o test-es5.js",
"cover": "babel-istanbul cover -x test-es5.js _mocha test-es5",
"cover": "nyc ava",
"lint": "node-version-gte-4 && eslint . || node-version-lt-4",
"precover": "npm run lint && npm run compile-test",
"prelint": "npm run clean",
"precover": "npm run lint && npm run clean",
"postcover": "nyc report -r html -r lcov",
"prepublish": "not-in-install && npm run compile || echo this is npm install",
"postpublish": "git push --follow-tags",
"pretest": "npm run lint",
"test": "mocha --compilers js:babel-register"
"test": "ava"
},
"ava": {
"require": [
"babel-register"
]
}
}
94 changes: 44 additions & 50 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,79 +1,73 @@
/* eslint-env mocha */
/* eslint import/no-extraneous-dependencies: ["error", { "devDependencies": true }] */

import test from 'ava';
import { CSSLint } from 'csslint';
import chalk from 'chalk';

import path from 'path';
import assert from 'assert';

import reporter from './stylish';

describe('csslint-stylish', () => {
it('should report stuff', () => {
const res = CSSLint.verify('.class {\n color: red !important\n}\n');
test('should report stuff', t => {
const res = CSSLint.verify('.class {\n color: red !important\n}\n');

let report = reporter.startFormat() + reporter.formatResults(res, path.resolve('style.css')) + reporter.endFormat();
let report = reporter.startFormat() + reporter.formatResults(res, path.resolve('style.css')) + reporter.endFormat();

report = chalk.stripColor(report);
report = chalk.stripColor(report);

const filename = report.split('\n')[1];
const filename = report.split('\n')[1];

assert(filename === 'style.css', 'filename is correct');
assert(report.match(/line 2/), 'report contains text');
assert(report.match(/char 3/), 'report contains text');
assert(report.match(/Use of !important/), 'report contains text');
assert(report.match(/1 warning/), 'report contains text');
});

it('should report with full path', () => {
const res = CSSLint.verify('.class {\n color: red !important\n}\n');

let report = reporter.startFormat() + reporter.formatResults(res, path.resolve('style.css'),
{ absoluteFilePathsForFormatters: true }) + reporter.endFormat();
t.true(filename === 'style.css', 'filename is correct');
t.regex(report, /line 2/, 'report contains text');
t.regex(report, /char 3/, 'report contains text');
t.regex(report, /Use of !important/, 'report contains text');
t.regex(report, /1 warning/, 'report contains text');
});

report = chalk.stripColor(report);
test('should report with full path', t => {
const res = CSSLint.verify('.class {\n color: red !important\n}\n');

const filename = report.split('\n')[1];
let report = reporter.startFormat() + reporter.formatResults(res, path.resolve('style.css'),
{ absoluteFilePathsForFormatters: true }) + reporter.endFormat();

assert(filename === path.join(__dirname, 'style.css'), 'filename is correct');
assert(report.match(/char 3/), 'report contains text');
assert(report.match(/Use of !important/), 'report contains text');
assert(report.match(/1 warning/), 'report contains text');
});
report = chalk.stripColor(report);

it('should be able to be registered as formatter', () => {
assert(!CSSLint.hasFormat('stylish'), 'csslint should not be stylish');
const filename = report.split('\n')[1];

CSSLint.addFormatter(reporter);
t.true(filename === path.join(__dirname, 'style.css'), 'filename is correct');
t.regex(report, /char 3/, 'report contains text');
t.regex(report, /Use of !important/, 'report contains text');
t.regex(report, /1 warning/, 'report contains text');
});

assert(CSSLint.hasFormat('stylish'), 'csslint should be stylish');
});
test('should be able to be registered as formatter', t => {
t.false(CSSLint.hasFormat('stylish'), 'csslint should not be stylish');

it('should not report undefined output lines when no filename provided', () => {
const res = CSSLint.verify('.class {\n color: red !important\n}\n');
CSSLint.addFormatter(reporter);

let report = reporter.startFormat() + reporter.formatResults(res) + reporter.endFormat();
t.true(CSSLint.hasFormat('stylish'), 'csslint should be stylish');
});

report = chalk.stripColor(report);
test('should not report undefined output lines when no filename provided', t => {
const res = CSSLint.verify('.class {\n color: red !important\n}\n');

const matches = report.match(/^undefined$/gm);
let report = reporter.startFormat() + reporter.formatResults(res) + reporter.endFormat();

assert(matches === null, 'report should not contains undefined text output');
});
report = chalk.stripColor(report);

it('should report filename provided', () => {
const res = CSSLint.verify('.class {\n color: red !important\n}\n');
const filename = path.resolve('filenamestyle.css');
let report = reporter.startFormat() + reporter.formatResults(res, filename,
{ absoluteFilePathsForFormatters: true }) + reporter.endFormat();
t.false(/^undefined$/gm.test(report), 'report should not contains undefined text output');
// t.notRegex(report, /^undefined$/gm, 'report should not contains undefined text output');
});

report = chalk.stripColor(report);
test('should report filename provided', t => {
const res = CSSLint.verify('.class {\n color: red !important\n}\n');
const filename = path.resolve('filenamestyle.css');
let report = reporter.startFormat() + reporter.formatResults(res, filename, { absoluteFilePathsForFormatters: true }) +
reporter.endFormat();

const matches = report.match(/^undefined$/gm);
const outfilename = report.split('\n')[1];
report = chalk.stripColor(report);

assert(matches === null, 'report should not contains undefined text output');
assert(outfilename === filename, 'filename should be in output lines');
});
// t.notRegex(report, /^undefined$/gm, 'report should not contains undefined text output');
t.false(/^undefined$/gm.test(report), 'report should not contains undefined text output');
t.true(report.split('\n')[1] === filename, 'filename should be in output lines');
});

0 comments on commit 1bb7c30

Please sign in to comment.