This repository has been archived by the owner on Nov 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
70 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
index.js | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"extends": "simenb-base" | ||
"extends": ["simenb-base", "simenb-ava"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ node_modules/ | |
.idea/ | ||
*.log | ||
coverage/ | ||
.nyc_output/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); |