@@ -4,79 +4,21 @@ import os = require('os');
44import path = require( 'path' ) ;
55import hc = require( '@actions/http-client' ) ;
66
7- import each from 'jest-each' ;
8-
97const toolDir = path . join ( __dirname , 'runner' , 'tools' ) ;
108const tempDir = path . join ( __dirname , 'runner' , 'temp' ) ;
119
1210process . env [ 'RUNNER_TOOL_CACHE' ] = toolDir ;
1311process . env [ 'RUNNER_TEMP' ] = tempDir ;
14- import * as setup from '../src/setup-dotnet' ;
1512import * as installer from '../src/installer' ;
1613
1714const IS_WINDOWS = process . platform === 'win32' ;
1815
19- describe ( 'version tests' , ( ) => {
20- each ( [ '3.1.999' , '3.1.101-preview.3' ] ) . test (
21- "Exact version '%s' should be the same" ,
22- vers => {
23- let versInfo = new installer . DotNetVersionInfo ( vers ) ;
24-
25- expect ( versInfo . isExactVersion ( ) ) . toBe ( true ) ;
26- expect ( versInfo . version ( ) ) . toBe ( vers ) ;
27- }
28- ) ;
29-
30- each ( [
31- [ '3.1.x' , '3.1' ] ,
32- [ '1.1.*' , '1.1' ] ,
33- [ '2.0' , '2.0' ]
34- ] ) . test ( "Generic version '%s' should be '%s'" , ( vers , resVers ) => {
35- let versInfo = new installer . DotNetVersionInfo ( vers ) ;
36-
37- expect ( versInfo . isExactVersion ( ) ) . toBe ( false ) ;
38- expect ( versInfo . version ( ) ) . toBe ( resVers ) ;
39- } ) ;
40-
41- each ( [
42- '' ,
43- '.' ,
44- '..' ,
45- ' . ' ,
46- '. ' ,
47- ' .' ,
48- ' . . ' ,
49- ' .. ' ,
50- ' . ' ,
51- '-1.-1' ,
52- '-1' ,
53- '-1.-1.-1' ,
54- '..3' ,
55- '1..3' ,
56- '1..' ,
57- '.2.3' ,
58- '.2.x' ,
59- '1' ,
60- '2.x' ,
61- '*.*.1' ,
62- '*.1' ,
63- '*.' ,
64- '1.2.' ,
65- '1.2.-abc' ,
66- 'a.b' ,
67- 'a.b.c' ,
68- 'a.b.c-preview' ,
69- ' 0 . 1 . 2 '
70- ] ) . test ( "Malformed version '%s' should throw" , vers => {
71- expect ( ( ) => new installer . DotNetVersionInfo ( vers ) ) . toThrow ( ) ;
72- } ) ;
73- } ) ;
74-
7516describe ( 'installer tests' , ( ) => {
7617 beforeAll ( async ( ) => {
7718 process . env . RUNNER_TOOL_CACHE = toolDir ;
7819 process . env . DOTNET_INSTALL_DIR = toolDir ;
7920 process . env . RUNNER_TEMP = tempDir ;
21+ process . env . DOTNET_ROOT = '' ;
8022 await io . rmRF ( toolDir ) ;
8123 await io . rmRF ( tempDir ) ;
8224 } ) ;
@@ -90,47 +32,6 @@ describe('installer tests', () => {
9032 }
9133 } , 30000 ) ;
9234
93- it ( 'Resolving a normal generic version works' , async ( ) => {
94- const dotnetInstaller = new installer . DotnetCoreInstaller ( '3.1.x' ) ;
95- let versInfo = await dotnetInstaller . resolveVersion (
96- new installer . DotNetVersionInfo ( '3.1.x' )
97- ) ;
98-
99- expect ( versInfo . startsWith ( '3.1.' ) ) ;
100- } , 100000 ) ;
101-
102- it ( 'Resolving a nonexistent generic version fails' , async ( ) => {
103- const dotnetInstaller = new installer . DotnetCoreInstaller ( '999.1.x' ) ;
104- try {
105- await dotnetInstaller . resolveVersion (
106- new installer . DotNetVersionInfo ( '999.1.x' )
107- ) ;
108- fail ( ) ;
109- } catch {
110- expect ( true ) ;
111- }
112- } , 100000 ) ;
113-
114- it ( 'Resolving a exact stable version works' , async ( ) => {
115- const dotnetInstaller = new installer . DotnetCoreInstaller ( '3.1.201' ) ;
116- let versInfo = await dotnetInstaller . resolveVersion (
117- new installer . DotNetVersionInfo ( '3.1.201' )
118- ) ;
119-
120- expect ( versInfo ) . toBe ( '3.1.201' ) ;
121- } , 100000 ) ;
122-
123- it ( 'Resolving a exact preview version works' , async ( ) => {
124- const dotnetInstaller = new installer . DotnetCoreInstaller (
125- '5.0.0-preview.6'
126- ) ;
127- let versInfo = await dotnetInstaller . resolveVersion (
128- new installer . DotNetVersionInfo ( '5.0.0-preview.6' )
129- ) ;
130-
131- expect ( versInfo ) . toBe ( '5.0.0-preview.6' ) ;
132- } , 100000 ) ;
133-
13435 it ( 'Acquires version of dotnet if no matching version is installed' , async ( ) => {
13536 await getDotnet ( '3.1.201' ) ;
13637 expect ( fs . existsSync ( path . join ( toolDir , 'sdk' , '3.1.201' ) ) ) . toBe ( true ) ;
@@ -139,24 +40,30 @@ describe('installer tests', () => {
13940 } else {
14041 expect ( fs . existsSync ( path . join ( toolDir , 'dotnet' ) ) ) . toBe ( true ) ;
14142 }
142- } , 400000 ) ; //This needs some time to download on "slower" internet connections
14343
144- it ( 'Acquires version of dotnet from global.json if no matching version is installed' , async ( ) => {
145- const globalJsonPath = path . join ( process . cwd ( ) , 'global.json' ) ;
146- const jsonContents = `{${ os . EOL } "sdk": {${ os . EOL } "version": "3.1.201"${ os . EOL } }${ os . EOL } }` ;
147- if ( ! fs . existsSync ( globalJsonPath ) ) {
148- fs . writeFileSync ( globalJsonPath , jsonContents ) ;
149- }
150- await setup . run ( ) ;
151-
152- expect ( fs . existsSync ( path . join ( toolDir , 'sdk' , '3.1.201' ) ) ) . toBe ( true ) ;
44+ expect ( process . env . DOTNET_ROOT ) . toBeDefined ;
45+ expect ( process . env . PATH ) . toBeDefined ;
46+ expect ( process . env . DOTNET_ROOT ) . toBe ( toolDir ) ;
47+ expect ( process . env . PATH ?. startsWith ( toolDir ) ) . toBe ( true ) ;
48+ } , 600000 ) ; //This needs some time to download on "slower" internet connections
49+
50+ it ( 'Acquires generic version of dotnet if no matching version is installed' , async ( ) => {
51+ await getDotnet ( '3.1' ) ;
52+ var directory = fs
53+ . readdirSync ( path . join ( toolDir , 'sdk' ) )
54+ . filter ( fn => fn . startsWith ( '3.1.' ) ) ;
55+ expect ( directory . length > 0 ) . toBe ( true ) ;
15356 if ( IS_WINDOWS ) {
15457 expect ( fs . existsSync ( path . join ( toolDir , 'dotnet.exe' ) ) ) . toBe ( true ) ;
15558 } else {
15659 expect ( fs . existsSync ( path . join ( toolDir , 'dotnet' ) ) ) . toBe ( true ) ;
15760 }
158- fs . unlinkSync ( globalJsonPath ) ;
159- } , 100000 ) ;
61+
62+ expect ( process . env . DOTNET_ROOT ) . toBeDefined ;
63+ expect ( process . env . PATH ) . toBeDefined ;
64+ expect ( process . env . DOTNET_ROOT ) . toBe ( toolDir ) ;
65+ expect ( process . env . PATH ?. startsWith ( toolDir ) ) . toBe ( true ) ;
66+ } , 600000 ) ; //This needs some time to download on "slower" internet connections
16067
16168 it ( 'Throws if no location contains correct dotnet version' , async ( ) => {
16269 let thrown = false ;
0 commit comments