Skip to content
Merged
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
12 changes: 8 additions & 4 deletions src/lib/eslint/BaseEslintEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import * as path from 'path';
// requires deleting DEFAULT_ENV_VARS, so be it.
// These are the environment variables that we'll want enabled by default in our ESLint baseConfig.
const DEFAULT_ENV_VARS: LooseObject = {
'es6': true, // `Map` class and others
'node': true, // `process` global var and others
'browser': true, // `document` global var
'webextensions': true // Chrome
es6: true, // `Map` class and others
node: true, // `process` global var and others
browser: true, // `document` global var
webextensions: true, // Chrome
jasmine: true, // `describe', 'expect', 'it' global vars
jest: true, // 'jest' global var
jquery: true, // '$' global var
mocha: true // `describe' and 'it' global vars
};

const ENV = 'env';
Expand Down
23 changes: 22 additions & 1 deletion test/code-fixtures/projects/js/src/baseConfigEnv.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,25 @@ var x = new Map(); // ex6
if (x) {
console.log(document.body); // browser
}
console.log(chrome.tabs); // webextensions
console.log(chrome.tabs); // webextensions

// 'describe', 'it', and 'expect' are jasmine keywords
// 'describe' and 'it' are mocha keywords
describe('In the Age of Ancients, the world was unformed and shrouded by fog.', () => {
it('A land of grey crags, arch trees, and everlasting dragons.', () => {
expect(true).toBe(true, 'Then there was Fire, and with Fire came disparity');
});
});

describe('Heat and cold; life and death; and of course, light and dark', () => {
it('And from the dark they came, and found the Souls of Lords within the flame', () => {
const lordSouls = ['Gravelord Nito, First of the Dead', 'The Witch of Izalith and her Daughters of Chaos',
'Gwynn, Lord of Sunlight and his faithful knights', 'The Furtive Pygmy, so easily forgotten'
];
expect(lordSouls.length).toBe(4, 'And with the strength of lords, they challenged the dragons');
});
});

$('.cssClass').show(); // JQuery

jest.useFakeTimers(); // Jest
14 changes: 0 additions & 14 deletions test/code-fixtures/projects/js/src/fileThatUsesJasmine.js

This file was deleted.

7 changes: 7 additions & 0 deletions test/code-fixtures/projects/js/src/fileThatUsesQUnit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Example from https://qunitjs.com/
const add = (a, b) => a + b;
QUnit.module('add', function() {
QUnit.test('should add two numbers', function(assert) {
assert.equal(add(1, 1), 2, '1 + 1 = 2');
});
});
15 changes: 8 additions & 7 deletions test/commands/scanner/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -826,16 +826,17 @@ describe('scanner:run', function () {
.stdout()
.stderr()
.command(['scanner:run',
'--target', path.join('test', 'code-fixtures', 'projects', 'js', 'src', 'fileThatUsesJasmine.js'),
'--target', path.join('test', 'code-fixtures', 'projects', 'js', 'src', 'fileThatUsesQUnit.js'),
'--format', 'json'
])
.it('By default, frameworks such as Jasmine are not included in the baseConfig', ctx => {
// We expect there to be 8 errors about jasmine-related syntax being undefined.
.it('By default, frameworks such as QUnit are not included in the baseConfig', ctx => {
// We expect there to be 2 errors about qunit-related syntax being undefined.
// There's currently some weird issue with the test framework that causes this specific execution to act
// like the --verbose flag was supplied. So we'll just pull out a JSON by getting everything from the first
// instance of '[' to the last instance of ']', since the JSON takes the form of an array.
const parsedCtx = JSON.parse(ctx.stdout.slice(ctx.stdout.indexOf('['), ctx.stdout.lastIndexOf(']') + 1));
expect(parsedCtx[0].violations.length).to.equal(6, 'Should be 6 violations');
expect(parsedCtx[0].violations.length).to.equal(2, `Should be 2 violations ${JSON.stringify(parsedCtx[0].violations)}`);
expect(parsedCtx[0].violations[0].message).to.contain("'QUnit' is not defined.");
});

// TODO: THIS TEST WAS IMPLEMENTED FOR W-7791882. THE FIX FOR THAT BUG WAS SUB-OPTIMAL AND WE NEED TO REDO IT IN 3.0.
Expand All @@ -845,11 +846,11 @@ describe('scanner:run', function () {
.stderr()

.command(['scanner:run',
'--target', path.join('test', 'code-fixtures', 'projects', 'js', 'src', 'fileThatUsesJasmine.js'),
'--target', path.join('test', 'code-fixtures', 'projects', 'js', 'src', 'fileThatUsesQUnit.js'),
'--format', 'json',
'--env', '{"jasmine": true}'
'--env', '{"qunit": true}'
])
.it('Providing jasmine in the --env override should resolve errors about that framework', ctx => {
.it('Providing qunit in the --env override should resolve errors about that framework', ctx => {
expect(ctx.stdout).to.contain('No rule violations found.', 'Should be no violations found in the file.');
});
});
Expand Down