Skip to content

Commit

Permalink
move cli.js from root to lib/
Browse files Browse the repository at this point in the history
  • Loading branch information
bartveneman committed Mar 8, 2019
1 parent 13c7249 commit 16f115c
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 32 deletions.
6 changes: 3 additions & 3 deletions cli.js → lib/cli.js
Expand Up @@ -12,13 +12,13 @@ const parseJson = require('parse-json')
const pathExists = require('path-exists')
const updateNotifier = require('update-notifier')

const flattenStats = require('./lib/flatten-stats')
const runTests = require('./lib/test-runner')
const flattenStats = require('./flatten-stats')
const runTests = require('./test-runner')
const {
MissingConfigException,
MissingCssException,
TestFailureException
} = require('./lib/exceptions')
} = require('./exceptions')

const readFileAsync = promisify(readFile)
const cli = meow(
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -4,7 +4,7 @@
"homepage": "https://www.projectwallace.com/oss",
"description": "A CSS complexity linter, based on css-analyzer.",
"bin": {
"constyble": "./cli.js"
"constyble": "./lib/cli.js"
},
"repository": "bartveneman/constyble",
"license": "MIT",
Expand Down
Binary file modified test/config-file/snapshots/spec.js.snap
Binary file not shown.
10 changes: 5 additions & 5 deletions test/config-file/spec.js
Expand Up @@ -6,7 +6,7 @@ const {MissingConfigException} = require('../../lib/exceptions')
const FIXTURE_CSS = 'body {\n\tcolor: blue;\n}\n'

test('it parses config with JSON comments without problems', async t => {
const {code, stdout} = await execa('../../cli.js', {
const {code, stdout} = await execa('../../lib/cli.js', {
input: FIXTURE_CSS,
cwd: __dirname
})
Expand All @@ -17,7 +17,7 @@ test('it parses config with JSON comments without problems', async t => {

test('it handles a custom config file correctly when a valid config path is given', async t => {
const {code, stdout} = await execa(
'./cli.js',
'./lib/cli.js',
['--config=test/config-file/config.json'],
{
input: FIXTURE_CSS
Expand All @@ -30,7 +30,7 @@ test('it handles a custom config file correctly when a valid config path is give

test('it shows a helpful error message when the custom config file cannot be found', async t => {
const {code, stderr} = await t.throwsAsync(
execa('./cli.js', {
execa('./lib/cli.js', {
input: FIXTURE_CSS
})
)
Expand All @@ -41,7 +41,7 @@ test('it shows a helpful error message when the custom config file cannot be fou

test('it reports an error if a config is not found when passed via --config', async t => {
const {code, stderr} = await t.throwsAsync(
execa('./cli.js', ['--config', 'config.json'], {
execa('./lib/cli.js', ['--config', 'config.json'], {
input: FIXTURE_CSS
})
)
Expand All @@ -52,7 +52,7 @@ test('it reports an error if a config is not found when passed via --config', as

test('it reports an error if a .constyblerc is not found in the current working directory', async t => {
const {code, stderr} = await t.throwsAsync(
execa('./cli.js', {
execa('./lib/cli.js', {
input: FIXTURE_CSS
})
)
Expand Down
16 changes: 8 additions & 8 deletions test/happy-path/snapshots/spec.js.md
Expand Up @@ -205,7 +205,7 @@ Generated by [AVA](https://ava.li).
module.exports␊
(constyble/lib/test-runner.js:14:32)␊
constyble/cli.js:80:21␊
constyble/lib/cli.js:80:21␊
source: |␊
test.ok(␊
...␊
Expand Down Expand Up @@ -235,7 +235,7 @@ Generated by [AVA](https://ava.li).
module.exports␊
(constyble/lib/test-runner.js:14:32)␊
constyble/cli.js:80:21␊
constyble/lib/cli.js:80:21␊
source: |␊
test.ok(␊
...␊
Expand Down Expand Up @@ -300,7 +300,7 @@ Generated by [AVA](https://ava.li).
module.exports␊
(constyble/lib/test-runner.js:14:32)␊
constyble/cli.js:80:21␊
constyble/lib/cli.js:80:21␊
source: |␊
test.ok(␊
...␊
Expand Down Expand Up @@ -330,7 +330,7 @@ Generated by [AVA](https://ava.li).
module.exports␊
(constyble/lib/test-runner.js:14:32)␊
constyble/cli.js:80:21␊
constyble/lib/cli.js:80:21␊
source: |␊
test.ok(␊
...␊
Expand Down Expand Up @@ -364,7 +364,7 @@ Generated by [AVA](https://ava.li).
module.exports␊
(constyble/lib/test-runner.js:14:32)␊
constyble/cli.js:80:21␊
constyble/lib/cli.js:80:21␊
source: |␊
test.equals(containsNoUnexpected(actual, expected), true)␊
...␊
Expand Down Expand Up @@ -504,7 +504,7 @@ Generated by [AVA](https://ava.li).
module.exports␊
(constyble/lib/test-runner.js:14:32)␊
constyble/cli.js:80:21␊
constyble/lib/cli.js:80:21␊
source: |␊
test.ok(␊
...␊
Expand Down Expand Up @@ -539,7 +539,7 @@ Generated by [AVA](https://ava.li).
module.exports␊
(constyble/lib/test-runner.js:14:32)␊
constyble/cli.js:80:21␊
constyble/lib/cli.js:80:21␊
source: |␊
test.ok(␊
...␊
Expand Down Expand Up @@ -674,7 +674,7 @@ Generated by [AVA](https://ava.li).
module.exports␊
(constyble/lib/test-runner.js:14:32)␊
constyble/cli.js:80:21␊
constyble/lib/cli.js:80:21␊
source: |␊
test.ok(␊
...␊
Expand Down
Binary file modified test/happy-path/snapshots/spec.js.snap
Binary file not shown.
18 changes: 11 additions & 7 deletions test/happy-path/spec.js
Expand Up @@ -8,7 +8,7 @@ const {
} = require('../../lib/exceptions')

test('it reports a success if all assertions pass with CSS via stdIn', async t => {
const {code, stdout} = await execa('../../cli.js', {
const {code, stdout} = await execa('../../lib/cli.js', {
input: 'body {\n\tcolor: blue;\n}\n',
cwd: __dirname
})
Expand All @@ -18,16 +18,20 @@ test('it reports a success if all assertions pass with CSS via stdIn', async t =
})

test('it reports a success if all assertions pass with a CSS file path as an argument', async t => {
const {stdout, code} = await execa('../../cli.js', ['fixture-success.css'], {
cwd: __dirname
})
const {stdout, code} = await execa(
'../../lib/cli.js',
['fixture-success.css'],
{
cwd: __dirname
}
)
t.is(code, 0)
t.snapshot(normalizeTapOutput(stdout))
})

test('it reports a failure if some assertions are exceeded', async t => {
const {code, stdout} = await t.throwsAsync(
execa('../../cli.js', {
execa('../../lib/cli.js', {
input: 'body {\n\tcolor: blue;\n\tmargin: 0;\n}\n',
cwd: __dirname
})
Expand All @@ -42,7 +46,7 @@ test('it reports a failure if some assertions are exceeded', async t => {

test('it reports an error if no css is passed but a .constyble is present', async t => {
const {stderr, code} = await t.throwsAsync(
execa('../../cli.js', {input: '', cwd: __dirname})
execa('../../lib/cli.js', {input: '', cwd: __dirname})
)

t.is(code, MissingCssException.code)
Expand All @@ -51,7 +55,7 @@ test('it reports an error if no css is passed but a .constyble is present', asyn

test('it handles invalid css', async t => {
const {code} = await t.throwsAsync(
execa('../../cli.js', {cwd: __dirname, input: 'a'})
execa('../../lib/cli.js', {cwd: __dirname, input: 'a'})
)

t.is(code, 1)
Expand Down
4 changes: 2 additions & 2 deletions test/help/spec.js
Expand Up @@ -2,14 +2,14 @@ const test = require('ava')
const execa = require('execa')

test('it shows a help message when called with --help', async t => {
const {stdout, code} = await execa('./cli.js', ['--help'])
const {stdout, code} = await execa('./lib/cli.js', ['--help'])

t.snapshot(stdout)
t.is(code, 0)
})

test('it shows a help message when called without arguments', async t => {
const {stdout, code} = await execa('./cli.js', {input: ''})
const {stdout, code} = await execa('./lib/cli.js', {input: ''})

t.snapshot(stdout)
t.is(code, 0)
Expand Down
4 changes: 2 additions & 2 deletions test/unknown-assertion/snapshots/spec.js.md
Expand Up @@ -30,7 +30,7 @@ Generated by [AVA](https://ava.li).
module.exports␊
(constyble/lib/test-runner.js:14:32)␊
constyble/cli.js:80:21␊
constyble/lib/cli.js:80:21␊
source: |␊
test.fail(␊
...␊
Expand Down Expand Up @@ -70,7 +70,7 @@ Generated by [AVA](https://ava.li).
module.exports␊
(constyble/lib/test-runner.js:14:32)␊
constyble/cli.js:80:21␊
constyble/lib/cli.js:80:21␊
source: |␊
test.fail(␊
...␊
Expand Down
Binary file modified test/unknown-assertion/snapshots/spec.js.snap
Binary file not shown.
4 changes: 2 additions & 2 deletions test/unknown-assertion/spec.js
Expand Up @@ -8,7 +8,7 @@ const FIXTURE_CSS = 'body {\n\tcolor: blue;\n}\n'

test('it fails the test if an unknown assertion is given in the config', async t => {
const {code, stdout} = await t.throwsAsync(
execa('../../cli.js', {
execa('../../lib/cli.js', {
input: FIXTURE_CSS,
cwd: __dirname
})
Expand All @@ -22,7 +22,7 @@ test('it fails the test if an unknown assertion is given in the config', async t

test('it shows an alternative assertion if a given one in the config cannot be found', async t => {
const {code, stdout} = await t.throwsAsync(
execa('../../cli.js', {
execa('../../lib/cli.js', {
input: FIXTURE_CSS,
cwd: __dirname
})
Expand Down
4 changes: 2 additions & 2 deletions test/version/spec.js
Expand Up @@ -3,14 +3,14 @@ const execa = require('execa')
const semver = require('semver')

test('it shows a valid version when passing --version', async t => {
const {stdout, code} = await execa('./cli.js', ['--version'])
const {stdout, code} = await execa('./lib/cli.js', ['--version'])

t.is(stdout, semver.valid(stdout))
t.is(code, 0)
})

test('it shows a valid version when passing -V', async t => {
const {stdout, code} = await execa('./cli.js', ['-V'])
const {stdout, code} = await execa('./lib/cli.js', ['-V'])

t.is(stdout, semver.valid(stdout))
t.is(code, 0)
Expand Down

0 comments on commit 16f115c

Please sign in to comment.