{"size": 1146, "ext": "js", "max_stars_repo_path": "nodejs-mobile/test/doctool/test-apilinks.js", "max_stars_repo_name": "xuelongqy/cnode", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "nodejs-mobile/test/doctool/test-apilinks.js", "max_issues_repo_name": "xuelongqy/cnode", "max_issues_repo_issues_event_min_datetime": "2020-03-13T14:45:49.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-15T16:31:22.000Z", "max_forks_repo_path": "nodejs-mobile/test/doctool/test-apilinks.js", "max_forks_repo_name": "xuelongqy/cnode", "max_forks_repo_forks_event_min_datetime": "2020-03-15T16:02:18.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-15T16:02:18.000Z"}
{"max_stars_count": null, "max_issues_count": 4, "max_forks_count": 1, "avg_line_length": 28.65, "max_line_length": 79, "alphanum_fraction": 0.6518324607}
'use strict';

require('../common');
const fixtures = require('../common/fixtures');
const fs = require('fs');
const assert = require('assert');
const path = require('path');
const { execFileSync } = require('child_process');

const script = path.join(__dirname, '..', '..', 'tools', 'doc', 'apilinks.js');

const apilinks = fixtures.path('apilinks');
fs.readdirSync(apilinks).forEach((fixture) => {
  if (!fixture.endsWith('.js')) return;
  const file = path.join(apilinks, fixture);

  const expectedContent = fs.readFileSync(file + 'on', 'utf8');

  const output = execFileSync(
    process.execPath,
    [script, file],
    { encoding: 'utf-8' }
  );

  const expectedLinks = JSON.parse(expectedContent);
  const actualLinks = JSON.parse(output);

  for (const [k, v] of Object.entries(expectedLinks)) {
    assert.ok(k in actualLinks, `link not found: ${k}`);
    assert.ok(actualLinks[k].endsWith('/' + v),
              `link ${actualLinks[k]} expected to end with ${v}`);
    delete actualLinks[k];
  }

  assert.strictEqual(
    Object.keys(actualLinks).length, 0,
    `unexpected links returned ${JSON.stringify(actualLinks)}`
  );
});
