updated unittests so that they work under both windows and linux/Mac

This commit is contained in:
Max Aigner 2023-12-15 14:33:02 +01:00
parent 1af6893043
commit d57e873329
3 changed files with 78 additions and 77 deletions

View File

@ -8,6 +8,7 @@ import {
getPlatform, getPlatform,
parseVersion parseVersion
} from '../src/utils' } from '../src/utils'
import normalizePath from 'normalize-path'
describe('parseVersion', () => { describe('parseVersion', () => {
test('parses valid godot versions', () => { test('parses valid godot versions', () => {
@ -172,116 +173,116 @@ describe('getExportTemplatePath', () => {
expect( expect(
getExportTemplatePath('4.0.0-beta1', getPlatform('linux'), true) getExportTemplatePath('4.0.0-beta1', getPlatform('linux'), true)
).toEqual( ).toEqual(
path.join( normalizePath(path.join(
os.homedir(), os.homedir(),
'.local/share/godot/export_templates', '.local', 'share','godot','export_templates',
'4.0.beta1.mono' '4.0.beta1.mono'
) ))
) )
expect( expect(
getExportTemplatePath('4.0.0-beta1', getPlatform('win32'), true) getExportTemplatePath('4.0.0-beta1', getPlatform('win32'), true)
).toEqual( ).toEqual(
path.join( normalizePath(path.join(
os.homedir(), os.homedir(),
'AppData/Roaming/Godot/export_templates', 'AppData','Roaming','Godot','export_templates',
'4.0.beta1.mono' '4.0.beta1.mono'
) ))
) )
expect( expect(
getExportTemplatePath('4.0.0-beta1', getPlatform('darwin'), true) getExportTemplatePath('4.0.0-beta1', getPlatform('darwin'), true)
).toEqual( ).toEqual(
path.join( normalizePath(path.join(
os.homedir(), os.homedir(),
'/Library/Application Support/Godot/export_templates', 'Library','Application Support','Godot','export_templates',
'4.0.beta1.mono' '4.0.beta1.mono'
) ))
) )
}) })
test('4.0.0', () => { test('4.0.0', () => {
expect( expect(
getExportTemplatePath('4.0.0', getPlatform('linux'), true) getExportTemplatePath('4.0.0', getPlatform('linux'), true)
).toEqual( ).toEqual(
path.join( normalizePath(path.join(
os.homedir(), os.homedir(),
'.local/share/godot/export_templates', '.local','share','godot','export_templates',
'4.0.stable.mono' '4.0.stable.mono'
) ))
) )
expect( expect(
getExportTemplatePath('4.0.0', getPlatform('win32'), true) getExportTemplatePath('4.0.0', getPlatform('win32'), true)
).toEqual( ).toEqual(
path.join( normalizePath(path.join(
os.homedir(), os.homedir(),
'AppData/Roaming/Godot/export_templates', 'AppData','Roaming','Godot','export_templates',
'4.0.stable.mono' '4.0.stable.mono'
) ))
) )
expect( expect(
getExportTemplatePath('4.0.0', getPlatform('darwin'), true) getExportTemplatePath('4.0.0', getPlatform('darwin'), true)
).toEqual( ).toEqual(
path.join( normalizePath(path.join(
os.homedir(), os.homedir(),
'/Library/Application Support/Godot/export_templates', 'Library','Application Support','Godot','export_templates',
'4.0.stable.mono' '4.0.stable.mono'
) ))
) )
}) })
test('3.5.1', () => { test('3.5.1', () => {
expect( expect(
getExportTemplatePath('3.5.1', getPlatform('linux'), true) getExportTemplatePath('3.5.1', getPlatform('linux'), true)
).toEqual( ).toEqual(
path.join( normalizePath(path.join(
os.homedir(), os.homedir(),
'.local/share/godot/templates', '.local','share','godot','templates',
'3.5.1.stable.mono' '3.5.1.stable.mono'
) ))
) )
expect( expect(
getExportTemplatePath('3.5.1', getPlatform('win32'), true) getExportTemplatePath('3.5.1', getPlatform('win32'), true)
).toEqual( ).toEqual(
path.join( normalizePath(path.join(
os.homedir(), os.homedir(),
'AppData/Roaming/Godot/templates', 'AppData','Roaming','Godot','templates',
'3.5.1.stable.mono' '3.5.1.stable.mono'
) ))
) )
expect( expect(
getExportTemplatePath('3.5.1', getPlatform('darwin'), true) getExportTemplatePath('3.5.1', getPlatform('darwin'), true)
).toEqual( ).toEqual(
path.join( normalizePath(path.join(
os.homedir(), os.homedir(),
'/Library/Application Support/Godot/templates', 'Library','Application Support','Godot','templates',
'3.5.1.stable.mono' '3.5.1.stable.mono'
) ))
) )
}) })
test('3.5.0', () => { test('3.5.0', () => {
expect( expect(
getExportTemplatePath('3.5.0', getPlatform('linux'), true) getExportTemplatePath('3.5.0', getPlatform('linux'), true)
).toEqual( ).toEqual(
path.join( normalizePath(path.join(
os.homedir(), os.homedir(),
'.local/share/godot/templates', '.local','share','godot','templates',
'3.5.stable.mono' '3.5.stable.mono'
) ))
) )
expect( expect(
getExportTemplatePath('3.5.0', getPlatform('win32'), true) getExportTemplatePath('3.5.0', getPlatform('win32'), true)
).toEqual( ).toEqual(
path.join( normalizePath(path.join(
os.homedir(), os.homedir(),
'AppData/Roaming/Godot/templates', 'AppData','Roaming','Godot','templates',
'3.5.stable.mono' '3.5.stable.mono'
) ))
) )
expect( expect(
getExportTemplatePath('3.5.0', getPlatform('darwin'), true) getExportTemplatePath('3.5.0', getPlatform('darwin'), true)
).toEqual( ).toEqual(
path.join( normalizePath(path.join(
os.homedir(), os.homedir(),
'/Library/Application Support/Godot/templates', 'Library','Application Support','Godot','templates',
'3.5.stable.mono' '3.5.stable.mono'
) ))
) )
}) })
}) })
@ -291,104 +292,104 @@ describe('getExportTemplatePath', () => {
expect( expect(
getExportTemplatePath('4.0.0-beta1', getPlatform('linux'), false) getExportTemplatePath('4.0.0-beta1', getPlatform('linux'), false)
).toEqual( ).toEqual(
path.join( normalizePath(path.join(
os.homedir(), os.homedir(),
'.local/share/godot/export_templates', '.local','share','godot','export_templates',
'4.0.beta1' '4.0.beta1'
) ))
) )
expect( expect(
getExportTemplatePath('4.0.0-beta1', getPlatform('win32'), false) getExportTemplatePath('4.0.0-beta1', getPlatform('win32'), false)
).toEqual( ).toEqual(
path.join( normalizePath(path.join(
os.homedir(), os.homedir(),
'AppData/Roaming/Godot/export_templates', 'AppData','Roaming','Godot','export_templates',
'4.0.beta1' '4.0.beta1'
) ))
) )
expect( expect(
getExportTemplatePath('4.0.0-beta1', getPlatform('darwin'), false) getExportTemplatePath('4.0.0-beta1', getPlatform('darwin'), false)
).toEqual( ).toEqual(
path.join( normalizePath(path.join(
os.homedir(), os.homedir(),
'/Library/Application Support/Godot/export_templates', 'Library','Application Support','Godot','export_templates',
'4.0.beta1' '4.0.beta1'
) ))
) )
}) })
test('4.0.0', () => { test('4.0.0', () => {
expect( expect(
getExportTemplatePath('4.0.0', getPlatform('linux'), false) getExportTemplatePath('4.0.0', getPlatform('linux'), false)
).toEqual( ).toEqual(
path.join( normalizePath(path.join(
os.homedir(), os.homedir(),
'.local/share/godot/export_templates', '.local','share','godot','export_templates',
'4.0.stable' '4.0.stable'
) ))
) )
expect( expect(
getExportTemplatePath('4.0.0', getPlatform('win32'), false) getExportTemplatePath('4.0.0', getPlatform('win32'), false)
).toEqual( ).toEqual(
path.join( normalizePath(path.join(
os.homedir(), os.homedir(),
'AppData/Roaming/Godot/export_templates', 'AppData','Roaming','Godot','export_templates',
'4.0.stable' '4.0.stable'
) ))
) )
expect( expect(
getExportTemplatePath('4.0.0', getPlatform('darwin'), false) getExportTemplatePath('4.0.0', getPlatform('darwin'), false)
).toEqual( ).toEqual(
path.join( normalizePath(path.join(
os.homedir(), os.homedir(),
'/Library/Application Support/Godot/export_templates', 'Library','Application Support','Godot','export_templates',
'4.0.stable' '4.0.stable'
) ))
) )
}) })
test('3.5.1', () => { test('3.5.1', () => {
expect( expect(
getExportTemplatePath('3.5.1', getPlatform('linux'), false) getExportTemplatePath('3.5.1', getPlatform('linux'), false)
).toEqual( ).toEqual(
path.join(os.homedir(), '.local/share/godot/templates', '3.5.1.stable') normalizePath(path.join(os.homedir(), '.local','share','godot','templates', '3.5.1.stable'))
) )
expect( expect(
getExportTemplatePath('3.5.1', getPlatform('win32'), false) getExportTemplatePath('3.5.1', getPlatform('win32'), false)
).toEqual( ).toEqual(
path.join( normalizePath(path.join(
os.homedir(), os.homedir(),
'AppData/Roaming/Godot/templates', 'AppData','Roaming','Godot','templates',
'3.5.1.stable' '3.5.1.stable'
) ))
) )
expect( expect(
getExportTemplatePath('3.5.1', getPlatform('darwin'), false) getExportTemplatePath('3.5.1', getPlatform('darwin'), false)
).toEqual( ).toEqual(
path.join( normalizePath(path.join(
os.homedir(), os.homedir(),
'/Library/Application Support/Godot/templates', 'Library','Application Support','Godot','templates',
'3.5.1.stable' '3.5.1.stable'
) ))
) )
}) })
test('3.5.0', () => { test('3.5.0', () => {
expect( expect(
getExportTemplatePath('3.5.0', getPlatform('linux'), false) getExportTemplatePath('3.5.0', getPlatform('linux'), false)
).toEqual( ).toEqual(
path.join(os.homedir(), '.local/share/godot/templates', '3.5.stable') normalizePath(path.join(os.homedir(), '.local','share','godot','templates', '3.5.stable'))
) )
expect( expect(
getExportTemplatePath('3.5.0', getPlatform('win32'), false) getExportTemplatePath('3.5.0', getPlatform('win32'), false)
).toEqual( ).toEqual(
path.join(os.homedir(), 'AppData/Roaming/Godot/templates', '3.5.stable') normalizePath(path.join(os.homedir(), 'AppData','Roaming','Godot','templates', '3.5.stable'))
) )
expect( expect(
getExportTemplatePath('3.5.0', getPlatform('darwin'), false) getExportTemplatePath('3.5.0', getPlatform('darwin'), false)
).toEqual( ).toEqual(
path.join( normalizePath(path.join(
os.homedir(), os.homedir(),
'/Library/Application Support/Godot/templates', 'Library','Application Support','Godot','templates',
'3.5.stable' '3.5.stable'
) ))
) )
}) })
}) })

2
package-lock.json generated
View File

@ -26,7 +26,7 @@
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"prettier": "^2.8.8", "prettier": "^2.8.8",
"ts-jest": "^29.1.0", "ts-jest": "^29.1.0",
"typescript": "^5.2.0" "typescript": "^5.2.2"
} }
}, },
"node_modules/@aashutoshrathi/word-wrap": { "node_modules/@aashutoshrathi/word-wrap": {

View File

@ -30,7 +30,7 @@ export interface Platform {
export class Linux implements Platform { export class Linux implements Platform {
GODOT_EXPORT_TEMPLATE_BASE_PATH = path.join( GODOT_EXPORT_TEMPLATE_BASE_PATH = path.join(
os.homedir(), os.homedir(),
'.local/share/godot' '.local','share','godot'
) )
godotFilenameSuffix(useDotnet: boolean): string { godotFilenameSuffix(useDotnet: boolean): string {
@ -53,7 +53,7 @@ export class Linux implements Platform {
export class Windows implements Platform { export class Windows implements Platform {
GODOT_EXPORT_TEMPLATE_BASE_PATH = path.normalize( GODOT_EXPORT_TEMPLATE_BASE_PATH = path.normalize(
path.join(os.homedir(), '\\AppData\\Roaming\\Godot') path.join(os.homedir(), 'AppData','Roaming','Godot')
) )
godotFilenameSuffix(useDotnet: boolean): string { godotFilenameSuffix(useDotnet: boolean): string {
@ -77,7 +77,7 @@ export class Windows implements Platform {
export class MacOS implements Platform { export class MacOS implements Platform {
GODOT_EXPORT_TEMPLATE_BASE_PATH = path.join( GODOT_EXPORT_TEMPLATE_BASE_PATH = path.join(
os.homedir(), os.homedir(),
'/Library/Application Support/Godot/' 'Library','Application Support','Godot'
) )
godotFilenameSuffix(useDotnet: boolean): string { godotFilenameSuffix(useDotnet: boolean): string {
@ -201,13 +201,13 @@ export function getExportTemplatePath(
} }
if (useDotnet) folderName += '.mono' if (useDotnet) folderName += '.mono'
return normalize( var exportTemplateFullPath = path.join(
path.join(
platform.GODOT_EXPORT_TEMPLATE_BASE_PATH, platform.GODOT_EXPORT_TEMPLATE_BASE_PATH,
version.major === '4' ? 'export_templates' : 'templates', version.major === '4' ? 'export_templates' : 'templates',
folderName folderName
) );
) var normalizedPath = normalize(exportTemplateFullPath)
return normalizedPath;
} }
export function getGodotFilename( export function getGodotFilename(