From 6e091a7cdbf134a7096b3fd24a7d2ed50b95ce6e Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Tue, 14 Jul 2020 14:20:51 +0200 Subject: [PATCH] test: update parser tests and snapshots --- .../__snapshots__/challengeSeed-to-data.test.js.snap | 6 +++--- .../__snapshots__/solution-to-data.test.js.snap | 11 ++++++++++- .../challenge-md-parser/challengeSeed-to-data.test.js | 7 ++++--- tools/challenge-md-parser/solution-to-data.test.js | 5 +++-- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/tools/challenge-md-parser/__snapshots__/challengeSeed-to-data.test.js.snap b/tools/challenge-md-parser/__snapshots__/challengeSeed-to-data.test.js.snap index 5c1226bca2..d3a51ee16b 100644 --- a/tools/challenge-md-parser/__snapshots__/challengeSeed-to-data.test.js.snap +++ b/tools/challenge-md-parser/__snapshots__/challengeSeed-to-data.test.js.snap @@ -2,8 +2,8 @@ exports[`challengeSeed-to-data plugin should have an output to match the snapshot 1`] = ` Object { - "files": Array [ - Object { + "files": Object { + "indexjs": Object { "contents": "function testFunction(arg) { return arg; } @@ -19,6 +19,6 @@ testFunction('hello'); "tail": "console.info('after the test'); ", }, - ], + }, } `; diff --git a/tools/challenge-md-parser/__snapshots__/solution-to-data.test.js.snap b/tools/challenge-md-parser/__snapshots__/solution-to-data.test.js.snap index 7557a5413c..941da1d057 100644 --- a/tools/challenge-md-parser/__snapshots__/solution-to-data.test.js.snap +++ b/tools/challenge-md-parser/__snapshots__/solution-to-data.test.js.snap @@ -3,12 +3,21 @@ exports[`challengeSeed-to-data plugin should have an output to match the snapshot 1`] = ` Object { "solutions": Array [ - "function testFunction(arg) { + Object { + "indexjs": Object { + "contents": "function testFunction(arg) { return arg; } testFunction('hello'); ", + "ext": "js", + "head": "", + "key": "indexjs", + "name": "index", + "tail": "", + }, + }, ], } `; diff --git a/tools/challenge-md-parser/challengeSeed-to-data.test.js b/tools/challenge-md-parser/challengeSeed-to-data.test.js index 5f2866d8b1..2cc99df3e0 100644 --- a/tools/challenge-md-parser/challengeSeed-to-data.test.js +++ b/tools/challenge-md-parser/challengeSeed-to-data.test.js @@ -3,6 +3,7 @@ const isArray = require('lodash/isArray'); const mockAST = require('./fixtures/challenge-html-ast.json'); const { challengeSeedToData } = require('./challengeSeed-to-data'); +const { isObject } = require('lodash'); describe('challengeSeed-to-data plugin', () => { const plugin = challengeSeedToData(); @@ -21,9 +22,9 @@ describe('challengeSeed-to-data plugin', () => { expect('files' in file.data).toBe(true); }); - it('ensures that the `files` property is an array', () => { + it('ensures that the `files` property is an object', () => { plugin(mockAST, file); - expect(Array.isArray(file.data.files)).toBe(true); + expect(isObject(file.data.files)).toBe(true); }); it('adds test objects to the files array following a schema', () => { @@ -32,7 +33,7 @@ describe('challengeSeed-to-data plugin', () => { const { data: { files } } = file; - const testObject = files[0]; + const testObject = files.indexjs; expect(Object.keys(testObject).length).toEqual(7); expect(testObject).toHaveProperty('key'); expect(typeof testObject['key']).toBe('string'); diff --git a/tools/challenge-md-parser/solution-to-data.test.js b/tools/challenge-md-parser/solution-to-data.test.js index a869d1c411..762a9186ff 100644 --- a/tools/challenge-md-parser/solution-to-data.test.js +++ b/tools/challenge-md-parser/solution-to-data.test.js @@ -1,6 +1,7 @@ /* global describe it expect beforeEach */ const mockAST = require('./fixtures/challenge-html-ast.json'); const solutionToData = require('./solution-to-data'); +const { isObject } = require('lodash'); describe('challengeSeed-to-data plugin', () => { const plugin = solutionToData(); @@ -24,10 +25,10 @@ describe('challengeSeed-to-data plugin', () => { expect(Array.isArray(file.data.solutions)).toBe(true); }); - it('each entry in the `solutions` array is a string', () => { + it('each entry in the `solutions` array is an object', () => { plugin(mockAST, file); - expect(file.data.solutions.every(el => typeof el === 'string')).toBe(true); + expect(file.data.solutions.every(el => isObject(el))).toBe(true); }); it('should have an output to match the snapshot', () => {