Skip to content

Commit

Permalink
New: Update init to search rules in npm.
Browse files Browse the repository at this point in the history
Fix: package.json files to copy all files.
Fix: A bunch of tests due to the new architecture.
  • Loading branch information
sarvaje committed Feb 9, 2018
1 parent 2231903 commit 515f075
Show file tree
Hide file tree
Showing 38 changed files with 1,168 additions and 424 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ dist
node_modules
npm-debug.log
yarn-error.log
**/.vscode/
2 changes: 1 addition & 1 deletion packages/rule-amp-validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"repository": "sonarwhal/sonarwhal",
"scripts": {
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"lint": "npm-run-all lint:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-apple-touch-icons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"repository": "sonarwhal/sonarwhal",
"scripts": {
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"lint": "npm-run-all lint:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-axe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"repository": "sonarwhal/sonarwhal",
"scripts": {
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"lint": "npm-run-all lint:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-content-type/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"repository": "sonarwhal/sonarwhal",
"scripts": {
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"lint": "npm-run-all lint:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-disown-opener/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"repository": "sonarwhal/sonarwhal",
"scripts": {
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"lint": "npm-run-all lint:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-highest-available-document-mode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"repository": "sonarwhal/sonarwhal",
"scripts": {
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"lint": "npm-run-all lint:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-html-checker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"repository": "sonarwhal/sonarwhal",
"scripts": {
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"lint": "npm-run-all lint:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-http-cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"repository": "sonarwhal/sonarwhal",
"scripts": {
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"lint": "npm-run-all lint:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-http-compression/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"repository": "sonarwhal/sonarwhal",
"scripts": {
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"lint": "npm-run-all lint:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-image-optimization-cloudinary/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"repository": "sonarwhal/sonarwhal",
"scripts": {
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"lint": "npm-run-all lint:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-manifest-app-name/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"repository": "sonarwhal/sonarwhal",
"scripts": {
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"lint": "npm-run-all lint:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-manifest-exists/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"repository": "sonarwhal/sonarwhal",
"scripts": {
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"lint": "npm-run-all lint:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-manifest-file-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"repository": "sonarwhal/sonarwhal",
"scripts": {
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"lint": "npm-run-all lint:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-manifest-is-valid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"repository": "sonarwhal/sonarwhal",
"scripts": {
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"lint": "npm-run-all lint:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-meta-charset-utf-8/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"repository": "sonarwhal/sonarwhal",
"scripts": {
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"lint": "npm-run-all lint:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-meta-viewport/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"repository": "sonarwhal/sonarwhal",
"scripts": {
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"lint": "npm-run-all lint:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-no-disallowed-headers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"repository": "sonarwhal/sonarwhal",
"scripts": {
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"lint": "npm-run-all lint:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-no-friendly-error-pages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"repository": "sonarwhal/sonarwhal",
"scripts": {
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"lint": "npm-run-all lint:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-no-html-only-headers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"repository": "sonarwhal/sonarwhal",
"scripts": {
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"lint": "npm-run-all lint:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-no-http-redirects/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"repository": "sonarwhal/sonarwhal",
"scripts": {
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"lint": "npm-run-all lint:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-no-protocol-relative-urls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"repository": "sonarwhal/sonarwhal",
"scripts": {
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"lint": "npm-run-all lint:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"repository": "sonarwhal/sonarwhal",
"scripts": {
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"lint": "npm-run-all lint:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-performance-budget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"repository": "sonarwhal/sonarwhal",
"scripts": {
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"lint": "npm-run-all lint:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-ssllabs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"scripts": {
"build-with-local-sonarwhal": "npm run -s link-sonarwhal; npm run build",
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"link-sonarwhal": "npm-link-check && npm link ../../../../ --ignore-scripts",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-strict-transport-security/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"scripts": {
"build-with-local-sonarwhal": "npm run -s link-sonarwhal; npm run build",
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"link-sonarwhal": "npm-link-check && npm link ../../../../ --ignore-scripts",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-validate-set-cookie-header/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"scripts": {
"build-with-local-sonarwhal": "npm run -s link-sonarwhal; npm run build",
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"link-sonarwhal": "npm-link-check && npm link ../../../../ --ignore-scripts",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-x-content-type-options/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"scripts": {
"build-with-local-sonarwhal": "npm run -s link-sonarwhal; npm run build",
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"link-sonarwhal": "npm-link-check && npm link ../../../../ --ignore-scripts",
Expand Down
17 changes: 16 additions & 1 deletion packages/sonarwhal/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
{
"ava": {
"failFast": false,
"files": [
"dist/tests/**/*.js"
],
"timeout": "1m"
},
"nyc": {
"extends": "../../.nycrc",
"include": [
"dist/tests/**/*.js"

]
},
"bin": "./dist/src/bin/sonarwhal.js",
"dependencies": {
"browserslist": "^2.11.3",
Expand Down Expand Up @@ -26,6 +40,7 @@
"lodash": "^4.17.5",
"mime-db": "^1.32.0",
"mkdirp": "^0.5.1",
"npm": "^5.6.0",
"optionator": "^0.8.2",
"ora": "^1.4.0",
"pluralize": "^7.0.0",
Expand Down Expand Up @@ -112,7 +127,7 @@
"scripts": {
"ava": "ava",
"build": "npm run clean && npm-run-all build:*",
"build:assets": "cpx \"./{src,tests}/**/!(*.ts)\" dist",
"build:assets": "cpx \"./{src,tests}/**/{!(*.ts),.!(ts)}\" dist",
"build:ts": "tsc",
"clean": "rimraf dist",
"lint": "npm-run-all lint:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export class Connector implements IConnector {
private _faviconLoaded: boolean = false;
/** The amount of time before an event is going to be timedout. */
private _timeout: number;
/** Browser PID */
private pid: number;

private _targetNetworkData: INetworkData;
private launcher: ILauncher;
Expand Down Expand Up @@ -647,6 +649,8 @@ export class Connector implements IConnector {
const launcher: BrowserInfo = await this.launcher.launch(this._options.useTabUrl ? this._options.tabUrl : 'about:blank');
let client;

this.pid = launcher.pid;

/*
* We want a new tab for this session. If it is a new browser, a new tab
* will be created automatically. If it was already there, then we need
Expand Down Expand Up @@ -888,6 +892,38 @@ export class Connector implements IConnector {
})();
}

private isClosed() {
return new Promise(async (resolve) => {
let maxTries = 200;
let finish = false;

while (!finish) {
try {
/*
* We test if the process is still running or is a leftover:
* https://nodejs.org/api/process.html#process_process_kill_pid_signal
*/

process.kill(this.pid, 0);

maxTries--;

// Wait for 10 seconds to close the browser or continue.
if (maxTries === 0) {
finish = true;
} else {
await delay(50);
}
} catch (e) {
debug(`Process with ${this.pid} doesn't seem to be running`);
finish = true;
}
}

resolve();
});
}

public async close() {
debug('Closing browsers used by CDP');

Expand All @@ -902,13 +938,16 @@ export class Connector implements IConnector {
}

try {

this._client.close();

/*
* We need this delay overall because in test if we close the
* client and at the same time the next test try to open a new
* tab then an error is thrown.
* We need to wait until the browser is close because
* in test if we close the client and at the same time
* the next test try to open a new tab then an error is
* thrown.
*/
await delay(300);
await this.isClosed();
} catch (e) {
debug(`Couldn't close the client properly`);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/sonarwhal/src/lib/utils/rule-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const getIncludedHeaders = (headers: object, headerList: Array<string> =
* * `/something/{rule,formatter,connector,parser}-another/` --> `another`
*/
export const getRuleName = (dirname: string): string => {
return path.basename(path.join(dirname, '../..')).replace(/(rule|formatter|connector|parser)-/, '');
return path.basename(path.join(dirname, '..')).replace(/(rule|formatter|connector|parser)-/, '');
};

/**
Expand Down
8 changes: 2 additions & 6 deletions packages/sonarwhal/tests/lib/cli/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,7 @@ test.serial(`if instalation fails, the user should show a message about how to i

t.true(t.context.logger.error.calledOnce);
t.is(errorMessage.message, 'Error installing packages');
t.true(installMessage.startsWith(`Something when wrong installing package, please run:
npm install @sonarwhal/rule-rule1 @sonarwhal/rule-rule2
to install all the rules.`));
t.true(installMessage.includes('npm install @sonarwhal/rule-rule1 @sonarwhal/rule-rule2'));

sandbox.restore();
});
Expand Down Expand Up @@ -312,9 +310,7 @@ test.serial(`if instalation fails and packages.json doesn't exist, the user shou

t.true(t.context.logger.error.calledOnce);
t.is(errorMessage.message, 'Error installing packages');
t.true(installMessage.includes(`Something when wrong installing package, please run:
npm install @sonarwhal/rule-rule1 @sonarwhal/rule-rule2 -g
to install all the rules.`));
t.true(installMessage.includes('npm install @sonarwhal/rule-rule1 @sonarwhal/rule-rule2 -g'));

sandbox.restore();
});
Expand Down
Loading

0 comments on commit 515f075

Please sign in to comment.