22 * Unit tests for src/config.ts
33 */
44
5+ import * as os from 'os'
56import * as fs from 'fs'
67import * as path from 'path'
78import { expect } from '@jest/globals'
@@ -14,36 +15,42 @@ describe('config.ts', () => {
1415 afterEach ( ( ) => fs . rmSync ( tempTestDir , { recursive : true , force : true } ) )
1516
1617 it ( 'Generate minimal configuration' , async ( ) => {
17- const modelicaFile = '/path/to/MyLibrary/package.mo'
18- const config : Configuration = {
19- library : ' MyLibrary',
20- libraryVersion : 'main' ,
21- loadFileCommands : [ `loadFile(" ${ path . resolve ( modelicaFile ) } ")` ]
18+ let modelicaFile : string
19+ if ( os . platform ( ) === 'win32' ) {
20+ modelicaFile = path . join ( 'C:' , 'path' , 'to' , ' MyLibrary', 'package.mo' )
21+ } else {
22+ modelicaFile = path . join ( '/path' , 'to' , 'MyLibrary' , 'package.mo' )
2223 }
23-
24- expect ( config ) . toEqual ( {
24+ const config = new Configuration ( {
2525 library : 'MyLibrary' ,
2626 libraryVersion : 'main' ,
27- loadFileCommands : [ ' loadFile("/path/to/MyLibrary/package.mo")' ]
27+ loadFileCommands : [ ` loadFile("${ modelicaFile } ")` ]
2828 } )
29+
30+ const expectedPath =
31+ os . platform ( ) === 'win32'
32+ ? 'C:/path/to/MyLibrary/package.mo'
33+ : '/path/to/MyLibrary/package.mo'
34+ expect ( config . loadFileCommands ) . toEqual ( [ `loadFile("${ expectedPath } ")` ] )
2935 } )
3036
3137 it ( 'Generate minimal configuration file' , async ( ) => {
3238 const file = path . join ( tempTestDir , 'testConfigSimple.json' )
33- const modelicaFile = '/ path/to/ MyLibrary/ package.mo'
34- const config : Configuration = {
39+ const modelicaFile = path . join ( ' path' , 'to' , ' MyLibrary' , ' package.mo')
40+ const config = new Configuration ( {
3541 library : 'MyLibrary' ,
3642 libraryVersion : 'main' ,
37- loadFileCommands : [ `loadFile("${ path . resolve ( modelicaFile ) } ")` ]
38- }
43+ loadFileCommands : [ `loadFile("${ modelicaFile } ")` ]
44+ } )
3945
4046 await genConfigFile ( file , [ config ] )
4147 expect ( fs . existsSync ( file ) ) . toBe ( true )
4248 } )
4349
4450 it ( 'Generate extensive configuration file' , async ( ) => {
4551 const file = path . join ( tempTestDir , 'testConfig.json' )
46- const config : Configuration = {
52+ const modelicaFile = path . join ( 'path' , 'to' , 'MyLibrary' , 'package.mo' )
53+ const config = new Configuration ( {
4754 library : 'MyLibrary' ,
4855 libraryVersion : 'main' ,
4956 libraryVersionNameForTests : 'v1.0.0-def' ,
@@ -69,7 +76,7 @@ describe('config.ts', () => {
6976 optlevel : '-Os -march=native' ,
7077 alarmFlag : '--alarm' ,
7178 abortSlowSimulation : '' ,
72- loadFileCommands : [ ' loadFile("${resolve( modelicaFile) }")' ] ,
79+ loadFileCommands : [ ` loadFile("${ modelicaFile } ")` ] ,
7380 extraCustomCommands : [ 'setCommandLineOptions("-d=-NLSanalyticJacobian")' ] ,
7481 environmentSimulation : [
7582 [ 'publicData' , '$libraryLocation/Tables/' ] ,
@@ -84,7 +91,7 @@ describe('config.ts', () => {
8491 ]
8592 ] ,
8693 configExtraName : 'noopt'
87- }
94+ } )
8895
8996 await genConfigFile ( file , [ config ] )
9097 expect ( fs . existsSync ( file ) ) . toBe ( true )
0 commit comments