Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Jun 27, 2017
1 parent 564258e commit bf5bd81
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lighthouse-cli/cli-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
35 changes: 35 additions & 0 deletions lighthouse-cli/test/cli/run-test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});

0 comments on commit bf5bd81

Please sign in to comment.