|
| 1 | +const fs = require('fs').promises; |
| 2 | +const path = require('path'); |
| 3 | +const { HtmlValidate } = require('html-validate'); |
| 4 | +const { getFormatter } = require('html-validate/dist/cli/formatter'); |
| 5 | +const { setUp } = require('./helpers'); |
| 6 | + |
| 7 | +const stylish = getFormatter('stylish'); |
| 8 | + |
| 9 | +const exercisesDir = path.join(__dirname, '../js-exercises/ex1-bookList'); |
| 10 | + |
| 11 | +const htmlValidate = new HtmlValidate({ |
| 12 | + extends: ['html-validate:recommended'], |
| 13 | + rules: { 'no-trailing-whitespace': 'off' }, |
| 14 | +}); |
| 15 | + |
| 16 | +describe('Generated HTML', () => { |
| 17 | + beforeAll(async () => { |
| 18 | + await fs.copyFile( |
| 19 | + path.join(exercisesDir, 'index.html'), |
| 20 | + './temp/index.html' |
| 21 | + ); |
| 22 | + await fs.copyFile(path.join(exercisesDir, 'index.js'), './temp/index.js'); |
| 23 | + |
| 24 | + await setUp(page); |
| 25 | + }); |
| 26 | + |
| 27 | + test('should be syntactically valid', async () => { |
| 28 | + const outerHTML = await page.evaluate( |
| 29 | + () => document.documentElement.outerHTML |
| 30 | + ); |
| 31 | + const htmlText = `<!DOCTYPE html>\n${outerHTML}`; |
| 32 | + const report = htmlValidate.validateString(htmlText); |
| 33 | + const validationReport = stylish(report); |
| 34 | + expect(validationReport).toBe(''); |
| 35 | + }); |
| 36 | + |
| 37 | + test('should contain an unordered list', async () => { |
| 38 | + const ul = await page.evaluate( |
| 39 | + () => document.querySelector('ul > li').outerHTML |
| 40 | + ); |
| 41 | + console.log(ul); |
| 42 | + }); |
| 43 | +}); |
0 commit comments