'use strict'; const common = require('../common'); const assert = require('assert'); const fs = require('fs'); const path = require('path'); // The doctool currently uses js-yaml from the tool/eslint/ tree. try { require('../../tools/eslint/node_modules/js-yaml'); } catch (e) { return common.skip('missing js-yaml (eslint not present)'); } const processIncludes = require('../../tools/doc/preprocess.js'); const html = require('../../tools/doc/html.js'); // Test data is a list of objects with two properties. // The file property is the file path. // The html property is some html which will be generated by the doctool. // This html will be stripped of all whitespace because we don't currently // have an html parser. const testData = [ { file: path.join(common.fixturesDir, 'sample_document.md'), html: '
  1. fish
  2. fish

  3. Redfish

  4. ' + '
  5. Bluefish
' }, { file: path.join(common.fixturesDir, 'order_of_end_tags_5873.md'), html: '

ClassMethod: Buffer.from(array) ' + '#

' }, { file: path.join(common.fixturesDir, 'doc_with_yaml.md'), html: '

Sample Markdown with YAML info' + '#

' + '

Foobar#

' + '
Added in: v1.0.0
' + '

Describe Foobar in more detail here.

' + '

Foobar II#

' + '
' + '
History' + '' + '' + '' + '
VersionChanges
v5.3.0, v4.2.0

Added in: v5.3.0, v4.2.0

' + '
v4.2.0

The error parameter can now be' + 'an arrow function.

' + '
' + '

Describe Foobar II in more detail here.' + 'fg(1)

' + '

Deprecated thingy#' + '

' + '
Added in: v1.0.0' + 'Deprecated since: v2.0.0

Describe ' + 'Deprecated thingy in more detail here.' + 'fg(1p)' + '

' + '

Something#

' + ' ' + '

Describe Something in more detail here. ' + '

' }, { file: path.join(common.fixturesDir, 'doc_with_includes.md'), html: '' + '

Look here!

' + '' + '' + '

foobar#

' + '

I exist and am being linked to.

' + '' }, { file: path.join(common.fixturesDir, 'sample_document.md'), html: '
  1. fish
  2. fish

  3. Redfish

  4. ' + '
  5. Bluefish
', analyticsId: 'UA-67020396-1' }, ]; testData.forEach((item) => { // Normalize expected data by stripping whitespace const expected = item.html.replace(/\s/g, ''); const includeAnalytics = typeof item.analyticsId !== 'undefined'; fs.readFile(item.file, 'utf8', common.mustCall((err, input) => { assert.ifError(err); processIncludes(item.file, input, common.mustCall((err, preprocessed) => { assert.ifError(err); html( { input: preprocessed, filename: 'foo', template: 'doc/template.html', nodeVersion: process.version, analytics: item.analyticsId, }, common.mustCall((err, output) => { assert.ifError(err); const actual = output.replace(/\s/g, ''); // Assert that the input stripped of all whitespace contains the // expected list assert.notStrictEqual(actual.indexOf(expected), -1); // Testing the insertion of Google Analytics script when // an analytics id is provided. Should not be present by default if (includeAnalytics) { assert.notStrictEqual(actual.indexOf('google-analytics.com'), -1, 'Google Analytics script was not present'); } else { assert.strictEqual(actual.indexOf('google-analytics.com'), -1, 'Google Analytics script was present'); } })); })); })); });