Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Asyncify the specs #74

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,23 @@ export default {

// Execute the Code Climate CLI, parse the results, and emit them to the
// Linter package as warnings. The Linter package handles the styling.

// eslint-disable-next-line no-console
console.log(`Running codeclimate: ${this.executablePath} ${execArgs.join(' ')}`);
let result;
try {
result = await Helpers.exec(this.executablePath, execArgs, execOpts);
} catch (e) {
notifyError(e, `${this.executablePath} ${execArgs.join(' ')}`);
// eslint-disable-next-line no-console
console.error('Error running codeclimate:', e);
return null;
}

// Handle unique spawning: killed execs will return null
if (result === null) {
// eslint-disable-next-line no-console
console.error('null result from exec');
return null;
}

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"devDependencies": {
"eslint": "^4.6.0",
"eslint-config-airbnb-base": "^12.0.0",
"eslint-plugin-import": "^2.7.0"
"eslint-plugin-import": "^2.7.0",
"jasmine-fix": "^1.3.1"
},
"scripts": {
"lint": "eslint .",
Expand Down
2 changes: 1 addition & 1 deletion spec/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
env: {
jasmine: true,
atomtest: true,
jasmine: true,
},
rules: {
"import/no-extraneous-dependencies": [
Expand Down
59 changes: 31 additions & 28 deletions spec/linter-codeclimate-spec.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
'use babel';

// eslint-disable-next-line no-unused-vars
import { it, fit, wait, beforeEach, afterEach } from 'jasmine-fix';
import { join } from 'path';

const { lint } = require('../lib/index.js').provideLinter();

const fixturesPath = join(__dirname, 'fixtures');
const coolCodePath = join(fixturesPath, 'cool_code.rb');
const TIMEOUT = process.env.CI ? 60000 : 10000;

describe('The codeclimate provider for Linter', () => {
const { lint } = require('../lib/index.js').provideLinter();
// Codeclimate can sometimes be quite slow (especially in a CI environment)
jasmine.getEnv().defaultTimeoutInterval = 60 * 1000; // 60 seconds

beforeEach(() => {
describe('The codeclimate provider for Linter', () => {
beforeEach(async () => {
atom.workspace.destroyActivePaneItem();

waitsForPromise(() =>
Promise.all([
atom.packages.activatePackage('linter-codeclimate'),
]));
await atom.packages.activatePackage('linter-codeclimate');
});

it('works with a valid .codeclimate.yml file', () =>
waitsForPromise(
{ timeout: TIMEOUT },
() =>
atom.workspace.open(coolCodePath).then(editor => lint(editor)).then((messages) => {
expect(messages[0].severity).toBe('warning');
expect(messages[0].excerpt).toBe('RUBOCOP: Unused method argument - ' +
"`bar`. If it's necessary, use `_` or `_bar` as an argument name to " +
"indicate that it won't be used. You can also write as `foo(*)` if " +
"you want the method to accept any arguments but don't care about " +
'them. [Rubocop/Lint/UnusedMethodArgument]');
expect(messages[0].description).toBeDefined();
expect(messages[0].reference).not.toBeDefined();
expect(messages[0].icon).not.toBeDefined();
expect(messages[0].solutions).not.toBeDefined();
expect(messages[0].location.file).toBe(coolCodePath);
expect(messages[0].location.position).toEqual([[1, 11], [1, 14]]);
}),
));
it('works with a valid .codeclimate.yml file', async () => {
// eslint-disable-next-line no-console
console.log('Started the spec...');
const editor = await atom.workspace.open(coolCodePath);
const messages = await lint(editor);
// eslint-disable-next-line no-console
console.log('Messages: ', JSON.stringify(messages, null, ' '));

expect(messages.length).toBe(1);
expect(messages[0].severity).toBe('warning');
expect(messages[0].excerpt).toBe('RUBOCOP: Unused method argument - ' +
"`bar`. If it's necessary, use `_` or `_bar` as an argument name to " +
"indicate that it won't be used. You can also write as `foo(*)` if " +
"you want the method to accept any arguments but don't care about " +
'them. [Rubocop/Lint/UnusedMethodArgument]');
expect(messages[0].description).toBeDefined();
expect(messages[0].reference).not.toBeDefined();
expect(messages[0].icon).not.toBeDefined();
expect(messages[0].solutions).not.toBeDefined();
expect(messages[0].location.file).toBe(coolCodePath);
expect(messages[0].location.position).toEqual([[1, 11], [1, 14]]);
});
});