@joseaburt/js-remote-code-evaluator
v0.1.1
Published
```js import { validateDOM, validateJS } from '../src/index';
Downloads
2
Readme
removete code validator
import { validateDOM, validateJS } from '../src/index';
it('validateDOM(challenge: IDOMChallenge, solution: string): Promise<IResult[]>', async () => {
const htmlChallenge = {
id: '241e649e-dfde-8962-8bd9-0e223f7c480d',
tests: [
{
id: '241e649e-dfde-8962-8bd9-0e412f7c480d',
given: `document.querySelector("p").textContent`,
expected: 'hello',
evaluation: 'lodash.isEqual(given, expected)',
},
{
id: '241e649e-dfde-8962-8bd9-0e412f7c220d',
given: `document.querySelector("p").classList[0]`,
expected: 'color-danger',
evaluation: 'lodash.includes(given, expected)',
},
{
id: '241e649e-dfde-8962-8bd9-0e412f7c980d',
given: `document.querySelector("p").textContent`,
expected: 'hello',
evaluation: 'lodash.isEqual(given, expected)',
},
],
};
const solution = `<p class="color-dandger" id="heading">hello</p>`;
const res = await validateDOM(htmlChallenge, solution);
expect(res[0]).toEqual(
expect.objectContaining({
errors: null,
isValid: true,
given: 'hello',
expected: 'hello',
})
);
expect(res[1]).toEqual(
expect.objectContaining({
errors: null,
isValid: false,
given: 'color-dandger',
expected: 'color-danger',
})
);
expect(res[2]).toEqual(
expect.objectContaining({
errors: null,
isValid: true,
given: 'hello',
expected: 'hello',
})
);
});
it('validate(challenge: IChallenge, solution: string, context?: any): Promise<IResult[]>', async () => {
const twoNumberSumChallenge = {
id: '234',
functionName: 'twoNumberSum',
validation: `lodash.isEqual(given.sort(), expected.sort())`,
tests: [
{
id: '1',
params: [[3, 5, -4, 8, 11, 1, -1, 6], 10],
expected: [-1, 11],
},
{
id: '2',
params: [[3, 5], 8],
expected: [3, 5],
},
],
};
const twoNumberSumSolution = `
function twoNumberSum(array, targetSum) {
let obj = {};
for (let i = 0; i < array.length; i++) {
const y = targetSum - array[i];
if (obj[y]) return [y, array[i]];
else obj[array[i]] = true;
}
return [];
}
`;
const res = await validateJS(twoNumberSumChallenge, twoNumberSumSolution);
expect(res[0]).toEqual(
expect.objectContaining({
isValid: true,
given: [-1, 11],
expected: [-1, 11],
})
);
expect(res[1]).toEqual(
expect.objectContaining({
isValid: true,
given: [3, 5],
expected: [3, 5],
})
);
});