Files
freeCodeCamp/tools/challenge-parser/parser/plugins/add-tests.test.js
Oliver Eyton-Williams e118dda13a fix: order imports and remove circular dependencies (#41824)
* fix: remove circular dependency

redux depended on templates/Challenges/redux and vice versa.  This
meant that import order mattered and confusing bugs could arise.

(cherry picked from commit 7d67a4e70922bbb3051f2f9982dcc69e240d43dc)

* feat: require imports to be in alphabetical order

Import order generally does not matter, but there are edge cases
(circular  imports and css imports, for example) where changing order
changes behaviour

(cherry picked from commit b8d1393a91ec6e068caf8e8498a5c95df68c2b2c)

* chore: order imports

* fix: lift up challenge description + title comps

This brings the classic Show closer to the others as they
now all create the description and title components

* fix: remove donation-saga/index circular import

(cherry picked from commit 51a44ca668a700786d2744feffeae4fdba5fd207)

* refactor: extract action-types from settings

(cherry picked from commit 25e26124d691c84a0d0827d41dafb761c686fadd)

* fix: lint errors

* feat: prevent useless renames
2021-08-02 08:39:40 -05:00

71 lines
2.0 KiB
JavaScript

const brokenHintsAST = require('../__fixtures__/ast-broken-hints.json');
const simpleAST = require('../__fixtures__/ast-simple.json');
const addTests = require('./add-tests');
describe('add-tests plugin', () => {
const plugin = addTests();
let file = { data: {} };
beforeEach(() => {
file = { data: {} };
});
it('returns a function', () => {
expect(typeof plugin).toEqual('function');
});
it('adds a `tests` property to `file.data`', () => {
plugin(simpleAST, file);
expect('tests' in file.data).toBe(true);
});
it('adds test objects to the tests array following a schema', () => {
expect.assertions(5);
plugin(simpleAST, file);
const testObject = file.data.tests[0];
expect(Object.keys(testObject).length).toBe(2);
expect(testObject).toHaveProperty('testString');
expect(typeof testObject.testString).toBe('string');
expect(testObject).toHaveProperty('text');
expect(typeof testObject.text).toBe('string');
});
// TODO: make this a bit more robust and informative
it('should throw if a test pair is out of order', () => {
expect.assertions(1);
expect(() => plugin(brokenHintsAST, file)).toThrow(
'testString (code block) is missing from hint'
);
});
it('preserves code whitespace in testStrings', () => {
plugin(simpleAST, file);
const testObject = file.data.tests[2];
expect(testObject.testString).toBe(`// more test code
if(let x of xs) {
console.log(x);
}`);
});
it('does not encode html', () => {
plugin(simpleAST, file);
const testObject = file.data.tests[1];
expect(testObject.text).toBe('<p>Second hint with <code>code</code></p>');
});
it('converts test text from md to html', () => {
plugin(simpleAST, file);
const testObject = file.data.tests[2];
expect(testObject.text).toBe(
'<p>Third <em>hint</em> with <code>code</code>' +
' and <code>inline code</code></p>'
);
});
it('should have an output to match the snapshot', () => {
plugin(simpleAST, file);
expect(file.data).toMatchSnapshot();
});
});