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