-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ Add more test case challenges to be resolved (#6)
* ✅ Add tests (jest) * ✅ Add a compound test case * Update ignore patterns of Eslint & Prettier * Rename answer key files from '.expect.js' to '.answerkey.js' * Rename answer key files from '.expect.js' to '.answerkey.js' * Add Node 10.x to CI test
- Loading branch information
1 parent
d448e9c
commit 5115d4d
Showing
26 changed files
with
300 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Main test script | ||
*/ | ||
|
||
const { vanilla } = require('../lib/vanilla'); | ||
const loadFileToBuffer = require('../lib/loadFileToBuffer'); | ||
|
||
describe("Test command 'vanilla'", () => { | ||
const testNames = ['documentReady']; | ||
|
||
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); | ||
|
||
// Expect | ||
expect(output).toEqual(answerKey); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
document.body.appendChild(document.createElement('p')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
$('body').append($('<p/>')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
var clonedElement = document.getElementById('about').cloneNode(true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
var clonedElement = $('#about').clone(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
$(document).ready(function () { | ||
$('body').bootstrapMaterialDesign(); | ||
|
||
(() => { | ||
$('#copy-to-username').click( | ||
/** @this HTMLElement */ | ||
function () { | ||
$('#target-username').val(() => | ||
$(this).prop('checked') ? $('#target-owner').val() : '' | ||
); | ||
} | ||
); | ||
|
||
$('#target-owner').keyup(() => { | ||
$('#copy-to-username').prop('checked') && | ||
$('#target-username').val($('#target-owner').val()); | ||
}); | ||
|
||
$('#target-username').keyup( | ||
/** @this HTMLElement */ | ||
function () { | ||
$('#copy-to-username').prop('checked', () => { | ||
return $(this).val() === $('#target-owner').val(); | ||
}); | ||
} | ||
); | ||
})(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
var newDiv = document.createElement('div') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
var divs = $('div'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
var footer = document.getElementById('footer'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
var footer = $('#footer'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
var parent = document.getElementById('something').parentNode; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
var parent = $('#something').parent(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
document.querySelectorAll(".box"); | ||
|
||
var divs = document.querySelectorAll('div'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
$(".box"); | ||
|
||
var divs = $('div'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Test function vanilla on case 'appendElement' | ||
*/ | ||
|
||
const { vanilla } = require('../../lib/vanilla'); | ||
const loadFileToBuffer = require('../../lib/loadFileToBuffer'); | ||
|
||
describe("Test command 'vanilla' on test challenges", () => { | ||
const testName = 'appendElement'; | ||
|
||
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Test function vanilla on case 'cloneElement' | ||
*/ | ||
|
||
const { vanilla } = require('../../lib/vanilla'); | ||
const loadFileToBuffer = require('../../lib/loadFileToBuffer'); | ||
|
||
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Test function vanilla on case 'createElement' | ||
*/ | ||
|
||
const { vanilla } = require('../../lib/vanilla'); | ||
const loadFileToBuffer = require('../../lib/loadFileToBuffer'); | ||
|
||
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Test function vanilla on case 'getElementById' | ||
*/ | ||
|
||
const { vanilla } = require('../../lib/vanilla'); | ||
const loadFileToBuffer = require('../../lib/loadFileToBuffer'); | ||
|
||
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Test function vanilla on case 'parent' | ||
*/ | ||
|
||
const { vanilla } = require('../../lib/vanilla'); | ||
const loadFileToBuffer = require('../../lib/loadFileToBuffer'); | ||
|
||
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Test function vanilla on case 'selectAll' | ||
*/ | ||
|
||
const { vanilla } = require('../../lib/vanilla'); | ||
const loadFileToBuffer = require('../../lib/loadFileToBuffer'); | ||
|
||
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
module.exports = { | ||
verbose: true, | ||
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$', | ||
testMatch: ['**/__tests__/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'], | ||
coveragePathIgnorePatterns: ['<rootDir>/__tests__/testChallenges/.*$'], | ||
testPathIgnorePatterns: ['(testCases).*$'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Loading a file to stream buffer | ||
* @param {string} answerKeyFile | ||
*/ | ||
|
||
const fs = require('fs'); | ||
|
||
module.exports = async (answerKeyFile) => { | ||
return new Promise((resolve) => { | ||
const stream = fs.createReadStream(answerKeyFile); | ||
stream.on('data', (buffer) => { | ||
resolve(buffer.toString()); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters