• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3require('../common');
4const assert = require('assert');
5const { spawnSync } = require('child_process');
6const fs = require('fs');
7const path = require('path');
8const tmpdir = require('../common/tmpdir');
9const util = require('util');
10
11const debuglog = util.debuglog('test');
12const versionsTool = path.resolve(__dirname, '../../tools/doc/versions.js');
13
14// At the time of writing these are the minimum expected versions.
15// New versions of Node.js do not have to be explicitly added here.
16const expected = [
17  '12.x',
18  '11.x',
19  '10.x',
20  '9.x',
21  '8.x',
22  '7.x',
23  '6.x',
24  '5.x',
25  '4.x',
26  '0.12.x',
27  '0.10.x',
28];
29
30tmpdir.refresh();
31const versionsFile = path.join(tmpdir.path, 'versions.json');
32debuglog(`${process.execPath} ${versionsTool} ${versionsFile}`);
33const opts = { cwd: tmpdir.path, encoding: 'utf8' };
34const cp = spawnSync(process.execPath, [ versionsTool, versionsFile ], opts);
35debuglog(cp.stderr);
36debuglog(cp.stdout);
37assert.strictEqual(cp.stdout, '');
38assert.strictEqual(cp.signal, null);
39assert.strictEqual(cp.status, 0);
40const versions = JSON.parse(fs.readFileSync(versionsFile));
41debuglog(versions);
42
43// Coherence checks for each returned version.
44for (const version of versions) {
45  const tested = util.inspect(version);
46  const parts = version.num.split('.');
47  const expectedLength = parts[0] === '0' ? 3 : 2;
48  assert.strictEqual(parts.length, expectedLength,
49                     `'num' from ${tested} should be '<major>.x'.`);
50  assert.strictEqual(parts[parts.length - 1], 'x',
51                     `'num' from ${tested} doesn't end in '.x'.`);
52  const isEvenRelease = Number.parseInt(parts[expectedLength - 2]) % 2 === 0;
53  const hasLtsProperty = version.hasOwnProperty('lts');
54  if (hasLtsProperty) {
55    // Odd-numbered versions of Node.js are never LTS.
56    assert.ok(isEvenRelease, `${tested} should not be an 'lts' release.`);
57    assert.ok(version.lts, `'lts' from ${tested} should 'true'.`);
58  }
59}
60
61// Check that the minimum number of versions were returned.
62// Later versions are allowed, but not checked for here (they were checked
63// above).
64// Also check for the previous semver major -- From master this will be the
65// most recent major release.
66const thisMajor = Number.parseInt(process.versions.node.split('.')[0]);
67const prevMajorString = `${thisMajor - 1}.x`;
68if (!expected.includes(prevMajorString)) {
69  expected.unshift(prevMajorString);
70}
71for (const version of expected) {
72  assert.ok(versions.find((x) => x.num === version),
73            `Did not find entry for '${version}' in ${util.inspect(versions)}`);
74}
75