Skip to content

Commit b659cb6

Browse files
committed
failing two tests... might be how im calling the script as well
1 parent 58023ee commit b659cb6

File tree

7 files changed

+128
-6
lines changed

7 files changed

+128
-6
lines changed

lib/test-utils/pwsh-test-mocha.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!pwsh.exe
2+
<#
3+
todo move this somewhere
4+
Test powershell inside of mocha... source and import?
5+
cd C:\Users\Jason\WebstormProjects\nuxt3-win32-posix-path
6+
pwsh.exe -File pwsh-test-mocha.ps1 c:\hi
7+
pwsh.exe -File lib/test-utils/pwsh-test-mocha.ps1 c:\hi s
8+
#>
9+
10+
# import-module -Name ./src/win32ToWin32WSL/win32ToWin32WSL2.ps1 -Function pathWin32ToPosix
11+
# source
12+
# powershell -Command ./src/win32ToWin32WSL/win32ToWin32WSL2.ps1; pathWin32ToPosix 'c:\hi'
13+
#write-host -NoNewline $args[0]
14+
. ./src/win32ToWin32WSL/win32ToWin32WSL2.ps1;
15+
$tmp=pathWin32ToPosix $args[0]
16+
write-host -NoNewline $tmp

src/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import {pathWin32ToPosix,pathPosixToWin32} from "#src/pathReplacement.mjs";
77
export {pathWin32ToPosix,pathPosixToWin32}
88

9-
import {win32ToWin32WSL2,win32ToWin32Slash} from "#src/win32ToWin32WSL2.mjs";
9+
import {win32ToWin32WSL2,win32ToWin32Slash} from "#src/win32ToWin32WSL/win32ToWin32WSL2.mjs";
1010
export {win32ToWin32WSL2,win32ToWin32Slash}
1111

1212
import {win32ToWin32JS} from "#src/win32ToWin32JS.mjs";
File renamed without changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<#
2+
#>
3+
function pathWin32ToPosix { #
4+
param($inPathWin32,$spaceEscape = "\ ") #
5+
$inPathWin32 = $inPathWin32.trim() #
6+
$inPathWin32 = $inPathWin32.Replace('\\','\')
7+
$inPathWin32 = $inPathWin32.Replace('\','/')
8+
$inPathWin32 = $inPathWin32.Replace(' ',$spaceEscape) # space escape
9+
$inPathWin32 = $inPathWin32 -replace "^[`"`']", '' # remove leading quotes
10+
$inPathWin32 = $inPathWin32 -replace "[`"`']$", '' # remove ending quotes
11+
12+
# .replace(/^["']/,'') #
13+
# .replace(/["']$/,'') #
14+
return $inPathWin32 #
15+
}
16+
#clear-host
17+
#pathWin32ToPosix 'C:/Users/username/Downloads/' # "C:/Users/username/Downloads/"

tests/concepts/nodePath.test.mjs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ import {posix,win32,sep} from 'node:path'
8080

8181
import {pathWin32ToPosix,pathPosixToWin32} from "##/src/pathReplacement.mjs"
8282
import {posixTests, win32Tests} from "##/lib/nodePathTestExamples.mjs";
83+
import {spawnSync} from "node:child_process";
8384

8485
/**
8586
* mobaxterm is /drives/c or cd c:/
@@ -131,3 +132,43 @@ describe('nodePath.test.mjs', function(){
131132
assert.strictEqual(sep,"\\")
132133
})
133134
});
135+
136+
const PathWin32ToPosixTests = [
137+
["C:\\Users\\Public\\Documents","C:/Users/Public/Documents"],//maybe append with quotes instead?
138+
["C:\\Users\\Public\\temp spaces\\a\\b c\\d","C:/Users/Public/temp\\ spaces/a/b\\ c/d"],
139+
["C:\\Users\\Public\\temp spaces\\a\\b c\\d","C:/Users/Public/temp\\ spaces/a/b\\ c/d"],
140+
["C:\\\\Users\\\\Public\\\\Documents","C:/Users/Public/Documents"]
141+
];
142+
const ogLength = PathWin32ToPosixTests.length
143+
for (let i = 0; i < ogLength; i++) {
144+
const row = PathWin32ToPosixTests[i];
145+
row[2] = i;
146+
PathWin32ToPosixTests.push([`'${row[0]}'`,row[1],`${i}1`]);//append with single quotes
147+
PathWin32ToPosixTests.push([`"${row[0]}"`,row[1],`${i}2`]);//append with double quotes
148+
149+
}
150+
describe('PathWin32ToPosixTests', function(){
151+
for (let i = 0; i < PathWin32ToPosixTests.length; i++) {
152+
// for (let i = 0; i < 1; i++) { //run only 1
153+
const [inputWinPath, expectedMntPath, win32ToPosixIndex] = PathWin32ToPosixTests[i];
154+
it(`PathWin32ToPosixTests MJS ${win32ToPosixIndex}`, function () {
155+
// console.log(wslPassTestIndex,inputWinPath);
156+
const actual = pathWin32ToPosix(inputWinPath);
157+
assert.strictEqual(actual,expectedMntPath);
158+
});
159+
it(`PathWin32ToPosixTests ps1 ${win32ToPosixIndex}`, function () {
160+
// console.log(wslPassTestIndex,inputWinPath);
161+
const output = spawnSync(`pwsh.exe -file lib/test-utils/pwsh-test-mocha.ps1`,[`"${inputWinPath}"`],{shell:true});
162+
// const output = spawnSync(`pwsh.exe -Command write-host ${inputWinPath}`,[],{shell:true});
163+
if(output.status !== 0){
164+
console.log(output.stdout.toString())
165+
console.error(output.stderr.toString())
166+
console.error(output.error,output.status)
167+
throw output.error
168+
}
169+
const actual = output.stdout.toString()
170+
171+
assert.strictEqual(actual,expectedMntPath);
172+
});
173+
}
174+
});

tests/unit/win32ToWin32WSL2.test.mjs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ this.timeout(500);//500ms
6565
*/
6666
import fs from 'node:fs';
6767
// import {win32ToWin32WSL2} from "##/dev/win-to-wsl/win32ToWin32WSL2.mjs";
68-
import {win32ToWin32Slash, win32ToWin32WSL2} from "#src/win32ToWin32WSL2.mjs";//fixme check the import subpath in package.json in other branch
68+
import {win32ToWin32Slash, win32ToWin32WSL2} from "##/src/win32ToWin32WSL/win32ToWin32WSL2.mjs";//fixme check the import subpath in package.json in other branch
6969
function writeToFile(fileName,data,space=2){
7070
const sFileName = /\./.test(fileName) ? fileName : fileName + '.json';
71-
const filePath = `dev/win-to-wsl/${sFileName}`
71+
const filePath = `temp/${sFileName}`
7272
fs.writeFileSync(filePath,
7373
typeof data === 'string' ? data :JSON.stringify(data,null,+space)
7474
);
@@ -77,6 +77,7 @@ function writeToFile(fileName,data,space=2){
7777
/**
7878
* To integrate and move with other tests
7979
*/
80+
8081
describe('win32ToWin32WSL2.test.mjs', function(){
8182
it('wsl', function(){
8283
//assert.strictEqual(1,1);//require assert
@@ -136,3 +137,47 @@ describe('win32ToWin32WSL2.test.mjs', function(){
136137
// because im reallocating and renaming / files and folders with spaces
137138

138139
});
140+
141+
142+
/**
143+
* wsl param tests
144+
*
145+
*/
146+
const WSLPassTests = [
147+
["C:\\Users\\Public\\Documents","/mnt/c/Users/Public/Documents"],//maybe append with quotes instead?
148+
["C:\\Users\\Public\\temp spaces\\a\\b c\\d","/mnt/c/Users/Public/temp\\ spaces/a/b\\ c/d"],
149+
["C:\\Users\\Public\\temp spaces\\a\\b c\\d","/mnt/c/Users/Public/temp\\ spaces/a/b\\ c/d"],
150+
["C:\\\\Users\\\\Public\\\\Documents","/mnt/c/Users/Public/Documents"],
151+
//todo look into thje backtick
152+
// ["C:\\Users\\Public\\temp` spaces\\a\\b` c\\d","/mnt/c/Users/Public/temp\\ spaces/a/b\\ c/d"],
153+
]
154+
//should work with changing the length of the array
155+
const ogLength = WSLPassTests.length
156+
for (let i = 0; i < ogLength; i++) {
157+
const row = WSLPassTests[i];
158+
row[2] = i;
159+
WSLPassTests.push([`'${row[0]}'`,row[1],`${i}1`]);//append with single quotes
160+
WSLPassTests.push([`"${row[0]}"`,row[1],`${i}2`]);//append with double quotes
161+
162+
}
163+
// writeToFile('WSLPassTests.jsonc',WSLPassTests);
164+
/**
165+
* parameterized tests
166+
*/
167+
import {spawnSync} from "node:child_process";
168+
169+
describe('WSLPassTests', function(){
170+
for (let i = 0; i < WSLPassTests.length; i++) {
171+
const [inputWinPath, expectedMntPath, wslPassTestIndex] = WSLPassTests[i];
172+
it(`WSLPassTests MJS ${wslPassTestIndex}`, function () {
173+
// console.log(wslPassTestIndex,inputWinPath);
174+
const actual = win32ToWin32WSL2(inputWinPath);
175+
assert.strictEqual(actual,expectedMntPath);
176+
});
177+
it(`WSLPassTests ps1 ${wslPassTestIndex}`, function () {
178+
// console.log(wslPassTestIndex,inputWinPath);
179+
const output = spawnSync(inputWinPath);
180+
assert.strictEqual(actual,expectedMntPath);
181+
});
182+
}
183+
});

vite.config.mjs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ export default defineConfig({
3535
formats: ['es', 'cjs'],//('es' | 'cjs' | 'umd' | 'iife')
3636
//i lost my jsdocs though... weird
3737
entry: [ //"entry" can be a dictionary or array of multiple entry points
38-
fileURLToPath(new URL('./src/index.mjs', import.meta.url)),
39-
fileURLToPath(new URL('./src/cli/index.mjs', import.meta.url)),
40-
// fileURLToPath(new URL('./dev/node-fs-utils-dev/create-dummy-files.mjs', import.meta.url)),
38+
// fileURLToPath(new URL('./src/index.mjs', import.meta.url)),
39+
// fileURLToPath(new URL('./src/win32ToWin32WSL/win32ToWin32WSL2.mjs', import.meta.url)),
40+
fileURLToPath(new URL('./temp/toWsl.mjs', import.meta.url)),
41+
// fileURLToPath(new URL('./src/cli/index.mjs', import.meta.url)),
42+
// fileURLToPath(new URL('./dev/node-fs-utils-dev/create-dummy-files.mjs
43+
// ', import.meta.url)),
4144
// fileURLToPath(new URL('./src/win32ToWin32WSL2.mjs', import.meta.url)),
4245
// fileURLToPath(new URL('./src/import-material-theme-pup.mjs', import.meta.url)),
4346
// resolve('src/import-theme-chrome-pup.mjs'),

0 commit comments

Comments
 (0)