Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔧 Organize code & centralize helper functions #24

Merged
merged 1 commit into from
Jul 23, 2020
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
6 changes: 5 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module.exports = {
env: { commonjs: true, node: true, es2020: true, jest: true },
extends: ['airbnb-base', 'plugin:prettier/recommended'],
extends: [
'airbnb-base',
'plugin:node/recommended',
'plugin:prettier/recommended',
],
globals: { Atomics: 'readonly', SharedArrayBuffer: 'readonly' },
parserOptions: { ecmaVersion: 2020, sourceType: 'module' },
rules: {
Expand Down
29 changes: 3 additions & 26 deletions __tests__/finishedTestChallenges/documentReady.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,7 @@
* Test function vanilla on case 'documentReady'
*/

const { vanilla } = require('../../lib/vanilla');
const loadFileToBuffer = require('../../lib/loadFileToBuffer');
const { testVanillaOnTestCase } = require('../lib/testCommandOnTestCase');

describe("Test command 'vanilla' on test challenges", () => {
const testName = 'documentReady';

test(`Vanillaize '${testName}'`, async () => {
// Input
const argv = {
_: ['vanilla', `./__tests__/testCases/${testName}.js`],
C: true,
'no-cache': true,
noCache: true,
$0: 'vaniquery',
};

// Output
const output = await vanilla(argv);

// Answer key
const answerKeyFile = `./__tests__/testCases/${testName}.answerkey.js`;
const answerKey = await loadFileToBuffer(answerKeyFile);

// Expect
expect(output).toEqual(answerKey);
});
});
const testCase = 'documentReady';
testVanillaOnTestCase(testCase);
29 changes: 3 additions & 26 deletions __tests__/finishedTestChallenges/getElementById.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,7 @@
* Test function vanilla on case 'getElementById'
*/

const { vanilla } = require('../../lib/vanilla');
const loadFileToBuffer = require('../../lib/loadFileToBuffer');
const { testVanillaOnTestCase } = require('../lib/testCommandOnTestCase');

describe("Test command 'vanilla' on test challenges", () => {
const testName = 'getElementById';

test(`Vanillaize '${testName}'`, async () => {
// Input
const argv = {
_: ['vanilla', `./__tests__/testCases/${testName}.js`],
C: true,
'no-cache': true,
noCache: true,
$0: 'vaniquery',
};

// Output
const output = await vanilla(argv);

// Answer key
const answerKeyFile = `./__tests__/testCases/${testName}.answerkey.js`;
const answerKey = await loadFileToBuffer(answerKeyFile);

// Expect
expect(output).toEqual(answerKey);
});
});
const testCase = 'getElementById';
testVanillaOnTestCase(testCase);
30 changes: 30 additions & 0 deletions __tests__/lib/testCommandOnTestCase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Test function vanilla on test case
*/

const { loadFileToBuffer } = require('../../lib/helpers');

exports.testVanillaOnTestCase = (testCase) => {
const { vanilla } = require('../../lib/vanilla'); // eslint-disable-line global-require

test(`Vanillaize '${testCase}'`, async () => {
// Input
const argv = {
_: ['vanilla', `./__tests__/testCases/${testCase}.js`],
C: true,
'no-cache': true,
noCache: true,
$0: 'vaniquery',
};

// Output
const output = await vanilla(argv);

// Answer key
const answerKeyFile = `./__tests__/testCases/${testCase}.answerkey.js`;
const answerKey = await loadFileToBuffer(answerKeyFile);

// Expect
expect(output).toEqual(answerKey);
});
};
35 changes: 6 additions & 29 deletions __tests__/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,14 @@
* Main test script
*/

const fs = require('fs');
const { vanilla } = require('../lib/vanilla');
const loadFileToBuffer = require('../lib/loadFileToBuffer');
const { testVanillaOnTestCase } = require('./lib/testCommandOnTestCase');
const { listAllFilesInDir } = require('../lib/helpers');

const testDir = './__tests__/finishedTestChallenges/';
const testNames = [];
fs.readdirSync(testDir).forEach((filename) => {
testNames.push(filename.substr(0, filename.indexOf('.test.js')));
});

describe("Test command 'vanilla'", () => {
testNames.forEach((testName) => {
test(`Vanillaize '${testName}'`, async () => {
// Input
const argv = {
_: ['vanilla', `./__tests__/testCases/${testName}.js`],
C: true,
'no-cache': true,
noCache: true,
$0: 'vaniquery',
};

// Output
const output = await vanilla(argv);

// Answer key
const answerKeyFile = `./__tests__/testCases/${testName}.answerkey.js`;
const answerKey = await loadFileToBuffer(answerKeyFile);
const testCases = listAllFilesInDir(testDir);

// Expect
expect(output).toEqual(answerKey);
});
describe("Test command 'vanilla' on several test cases", () => {
testCases.forEach((testCase) => {
testVanillaOnTestCase(testCase);
});
});
29 changes: 3 additions & 26 deletions __tests__/pendingTestChallenges/children.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,7 @@
* Test function vanilla on case 'children'
*/

const { vanilla } = require('../../lib/vanilla');
const loadFileToBuffer = require('../../lib/loadFileToBuffer');
const { testVanillaOnTestCase } = require('../lib/testCommandOnTestCase');

describe("Test command 'vanilla' on test challenges", () => {
const testName = 'children';

test(`Vanillaize '${testName}'`, async () => {
// Input
const argv = {
_: ['vanilla', `./__tests__/testCases/${testName}.js`],
C: true,
'no-cache': true,
noCache: true,
$0: 'vaniquery',
};

// Output
const output = await vanilla(argv);

// Answer key
const answerKeyFile = `./__tests__/testCases/${testName}.answerkey.js`;
const answerKey = await loadFileToBuffer(answerKeyFile);

// Expect
expect(output).toEqual(answerKey);
});
});
const testCase = 'children';
testVanillaOnTestCase(testCase);
29 changes: 3 additions & 26 deletions __tests__/pendingTestChallenges/cloneElement.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,7 @@
* Test function vanilla on case 'cloneElement'
*/

const { vanilla } = require('../../lib/vanilla');
const loadFileToBuffer = require('../../lib/loadFileToBuffer');
const { testVanillaOnTestCase } = require('../lib/testCommandOnTestCase');

describe("Test command 'vanilla' on test challenges", () => {
const testName = 'cloneElement';

test(`Vanillaize '${testName}'`, async () => {
// Input
const argv = {
_: ['vanilla', `./__tests__/testCases/${testName}.js`],
C: true,
'no-cache': true,
noCache: true,
$0: 'vaniquery',
};

// Output
const output = await vanilla(argv);

// Answer key
const answerKeyFile = `./__tests__/testCases/${testName}.answerkey.js`;
const answerKey = await loadFileToBuffer(answerKeyFile);

// Expect
expect(output).toEqual(answerKey);
});
});
const testCase = 'cloneElement';
testVanillaOnTestCase(testCase);
29 changes: 3 additions & 26 deletions __tests__/pendingTestChallenges/createElement.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,7 @@
* Test function vanilla on case 'createElement'
*/

const { vanilla } = require('../../lib/vanilla');
const loadFileToBuffer = require('../../lib/loadFileToBuffer');
const { testVanillaOnTestCase } = require('../lib/testCommandOnTestCase');

describe("Test command 'vanilla' on test challenges", () => {
const testName = 'createElement';

test(`Vanillaize '${testName}'`, async () => {
// Input
const argv = {
_: ['vanilla', `./__tests__/testCases/${testName}.js`],
C: true,
'no-cache': true,
noCache: true,
$0: 'vaniquery',
};

// Output
const output = await vanilla(argv);

// Answer key
const answerKeyFile = `./__tests__/testCases/${testName}.answerkey.js`;
const answerKey = await loadFileToBuffer(answerKeyFile);

// Expect
expect(output).toEqual(answerKey);
});
});
const testCase = 'createElement';
testVanillaOnTestCase(testCase);
29 changes: 3 additions & 26 deletions __tests__/pendingTestChallenges/getElementsByClassName.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,7 @@
* Test function vanilla on case 'getElementsByClassName'
*/

const { vanilla } = require('../../lib/vanilla');
const loadFileToBuffer = require('../../lib/loadFileToBuffer');
const { testVanillaOnTestCase } = require('../lib/testCommandOnTestCase');

describe("Test command 'vanilla' on test challenges", () => {
const testName = 'getElementsByClassName';

test(`Vanillaize '${testName}'`, async () => {
// Input
const argv = {
_: ['vanilla', `./__tests__/testCases/${testName}.js`],
C: true,
'no-cache': true,
noCache: true,
$0: 'vaniquery',
};

// Output
const output = await vanilla(argv);

// Answer key
const answerKeyFile = `./__tests__/testCases/${testName}.answerkey.js`;
const answerKey = await loadFileToBuffer(answerKeyFile);

// Expect
expect(output).toEqual(answerKey);
});
});
const testCase = 'getElementsByClassName';
testVanillaOnTestCase(testCase);
29 changes: 3 additions & 26 deletions __tests__/pendingTestChallenges/getElementsByTagName.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,7 @@
* Test function vanilla on case 'getElementsByTagName'
*/

const { vanilla } = require('../../lib/vanilla');
const loadFileToBuffer = require('../../lib/loadFileToBuffer');
const { testVanillaOnTestCase } = require('../lib/testCommandOnTestCase');

describe("Test command 'vanilla' on test challenges", () => {
const testName = 'getElementsByTagName';

test(`Vanillaize '${testName}'`, async () => {
// Input
const argv = {
_: ['vanilla', `./__tests__/testCases/${testName}.js`],
C: true,
'no-cache': true,
noCache: true,
$0: 'vaniquery',
};

// Output
const output = await vanilla(argv);

// Answer key
const answerKeyFile = `./__tests__/testCases/${testName}.answerkey.js`;
const answerKey = await loadFileToBuffer(answerKeyFile);

// Expect
expect(output).toEqual(answerKey);
});
});
const testCase = 'getElementsByTagName';
testVanillaOnTestCase(testCase);
29 changes: 3 additions & 26 deletions __tests__/pendingTestChallenges/parent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,7 @@
* Test function vanilla on case 'parent'
*/

const { vanilla } = require('../../lib/vanilla');
const loadFileToBuffer = require('../../lib/loadFileToBuffer');
const { testVanillaOnTestCase } = require('../lib/testCommandOnTestCase');

describe("Test command 'vanilla' on test challenges", () => {
const testName = 'parent';

test(`Vanillaize '${testName}'`, async () => {
// Input
const argv = {
_: ['vanilla', `./__tests__/testCases/${testName}.js`],
C: true,
'no-cache': true,
noCache: true,
$0: 'vaniquery',
};

// Output
const output = await vanilla(argv);

// Answer key
const answerKeyFile = `./__tests__/testCases/${testName}.answerkey.js`;
const answerKey = await loadFileToBuffer(answerKeyFile);

// Expect
expect(output).toEqual(answerKey);
});
});
const testCase = 'parent';
testVanillaOnTestCase(testCase);
29 changes: 3 additions & 26 deletions __tests__/pendingTestChallenges/selectAll.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,7 @@
* Test function vanilla on case 'selectAll'
*/

const { vanilla } = require('../../lib/vanilla');
const loadFileToBuffer = require('../../lib/loadFileToBuffer');
const { testVanillaOnTestCase } = require('../lib/testCommandOnTestCase');

describe("Test command 'vanilla' on test challenges", () => {
const testName = 'selectAll';

test(`Vanillaize '${testName}'`, async () => {
// Input
const argv = {
_: ['vanilla', `./__tests__/testCases/${testName}.js`],
C: true,
'no-cache': true,
noCache: true,
$0: 'vaniquery',
};

// Output
const output = await vanilla(argv);

// Answer key
const answerKeyFile = `./__tests__/testCases/${testName}.answerkey.js`;
const answerKey = await loadFileToBuffer(answerKeyFile);

// Expect
expect(output).toEqual(answerKey);
});
});
const testCase = 'selectAll';
testVanillaOnTestCase(testCase);
Loading