diff --git a/lighthouse-cli/cli-flags.ts b/lighthouse-cli/cli-flags.ts index 2352f31aa9f2..3261349a4910 100644 --- a/lighthouse-cli/cli-flags.ts +++ b/lighthouse-cli/cli-flags.ts @@ -17,8 +17,10 @@ export interface Flags { view: boolean, maxWaitForLoad: number } -export function getFlags() { - return yargs.help('help') +export function getFlags(fakeInput?: string) { + const y = fakeInput ? yargs(fakeInput) : yargs; + + return y.help('help') .version(() => pkg.version) .showHelpOnFail(false, 'Specify --help for available options') diff --git a/lighthouse-cli/package.json b/lighthouse-cli/package.json index f1c1cc81332c..9eed1c7328a6 100644 --- a/lighthouse-cli/package.json +++ b/lighthouse-cli/package.json @@ -5,7 +5,7 @@ "scripts": { "build": "tsc", "dev": "tsc -w", - "test": "mocha --reporter dot test/**/*-test.js", + "test": "mocha --reporter dot test/**/*-test.js --timeout 15000", "coverage": "nyc yarn test && nyc report --reporter=text-lcov > lcov.info", "test-formatting": "./test/check-formatting.sh", "format": "clang-format -i -style=file *.ts **/*.ts" diff --git a/lighthouse-cli/test/cli/run-test.js b/lighthouse-cli/test/cli/run-test.js new file mode 100644 index 000000000000..ad8ccf34f062 --- /dev/null +++ b/lighthouse-cli/test/cli/run-test.js @@ -0,0 +1,35 @@ +/** + * @license Copyright 2016 Google Inc. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + */ +'use strict'; + +/* eslint-env mocha */ +const assert = require('assert'); +const path = require('path'); +const fs = require('fs'); + +const run = require('../../run'); +const fastConfig = { + 'extends': 'lighthouse:default', + 'settings': { + 'onlyAudits': ['viewport'] + } +}; + +const getFlags = require('../../cli-flags').getFlags; + +describe('CLI run', function() { + it('runLighthouse completes a LH round trip', () => { + const url = 'chrome://version'; + const filename = path.join(process.cwd(), 'run.ts.results.json'); + const flags = getFlags(`--output=json --output-path=${filename} ${url}`); + return run.runLighthouse(url, flags, fastConfig).then(_ => { + assert.ok(fs.existsSync(filename)); + const results = JSON.parse(fs.readFileSync(filename, 'utf-8')); + assert.equal(results.audits.viewport.rawValue, false); + fs.unlinkSync(filename); + }); + }); +});