Skip to content

Commit 8f3acac

Browse files
authored
Merge pull request #10 from codeforwings/jc-dev-spawnCmd-tests
Jc dev spawn cmd tests
2 parents f49330f + 73e87a0 commit 8f3acac

16 files changed

+608
-49
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ dist
1111
/docs/.vitepress/dist/
1212
/dev/win-to-wsl/logs/
1313
/temp/
14+
/dev/node-fs-utils-dev/tests/dev-specific/temp/

.run/ghGenerateAndDeploy.run.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="ghGenerateAndDeploy" type="js.build_tools.npm" nameIsGenerated="true">
3+
<package-json value="$PROJECT_DIR$/package.json" />
4+
<command value="run" />
5+
<scripts>
6+
<script value="ghGenerateAndDeploy" />
7+
</scripts>
8+
<node-interpreter value="project" />
9+
<envs />
10+
<method v="2" />
11+
</configuration>
12+
</component>

.run/spawncmd empty env.run.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="spawncmd empty env" type="mocha-javascript-test-runner" nameIsGenerated="true">
3+
<node-interpreter>project</node-interpreter>
4+
<node-options />
5+
<mocha-package>$PROJECT_DIR$/node_modules/mocha</mocha-package>
6+
<working-directory>$PROJECT_DIR$</working-directory>
7+
<pass-parent-env>false</pass-parent-env>
8+
<ui>bdd</ui>
9+
<extra-mocha-options />
10+
<test-kind>SUITE</test-kind>
11+
<test-file>$PROJECT_DIR$/dev/node-fs-utils-dev/tests/dev-specific/spawnCmd-cwd.test.mjs</test-file>
12+
<test-names>
13+
<name value="spawncmd empty env" />
14+
</test-names>
15+
<method v="2" />
16+
</configuration>
17+
</component>

.run/try pwd (no env)_.run.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="try pwd (no env)_" type="mocha-javascript-test-runner">
3+
<node-interpreter>project</node-interpreter>
4+
<node-options />
5+
<mocha-package>$PROJECT_DIR$/node_modules/mocha</mocha-package>
6+
<working-directory>$PROJECT_DIR$</working-directory>
7+
<pass-parent-env>false</pass-parent-env>
8+
<ui>bdd</ui>
9+
<extra-mocha-options />
10+
<test-kind>TEST</test-kind>
11+
<test-file>$PROJECT_DIR$/dev/node-fs-utils-dev/tests/dev-specific/spawnCmd-cwd.test.mjs</test-file>
12+
<test-names>
13+
<name value="spawncmd empty env" />
14+
<name value="try pwd no env" />
15+
</test-names>
16+
<method v="2" />
17+
</configuration>
18+
</component>

app.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,12 @@
5454
// import {win32ToWin32Slash, win32ToWin32WSL2} from "~/src/win32ToWin32WSL2.mjs";
5555
5656
import {posixTests, win32Tests} from "~/lib/nodePathTestExamples.mjs";
57+
import {pathPosixToWin32, pathWin32ToPosix,win32ToWin32JS,win32ToWin32Slash,win32ToWin32WSL2} from "~/lib/dist/index.mjs";
58+
59+
//## not working for some reason
5760
// import {posixTests, win32Tests} from "##/lib/nodePathTestExamples.mjs";
5861
// import {pathPosixToWin32, pathWin32ToPosix,win32ToWin32JS,win32ToWin32Slash,win32ToWin32WSL2} from "##/lib/dist/index.mjs";
59-
import {pathPosixToWin32, pathWin32ToPosix,win32ToWin32JS,win32ToWin32Slash,win32ToWin32WSL2} from "##/lib/dist/index.mjs";
62+
// import {pathPosixToWin32, pathWin32ToPosix,win32ToWin32JS,win32ToWin32Slash,win32ToWin32WSL2} from "##/lib/dist/index.mjs";
6063
export default {
6164
name:'app',
6265
mounted(){
@@ -82,7 +85,11 @@ export default {
8285
[
8386
"C:\\Users\\Public\\Documents",
8487
"C:\\\\Users\\\\Public\\\\Documents",
85-
"C:\\Users\\Public\\temp spaces\\a\\b c\\d"
88+
"C:\\Users\\Public\\temp spaces\\a\\b c\\d",
89+
`"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"`,
90+
`C:\\progra~1\\PowerShell\\7\\pwsh.exe`,
91+
`C:\\cygwin64\\bin\\bash.exe`,
92+
`C:\\Windows\\System32\\cmd.exe`
8693
].join('\n'),
8794
}
8895
},

dev/node-fs-utils-dev/SpawnCmd.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ import { spawn } from 'node:child_process'
1111
import {stdout,stderr} from 'node:process'
1212

1313
/** might be better just to use buffer like they are */
14+
/**
15+
*
16+
* @param cmd
17+
* @param args
18+
* @param opts - {shell:true} or path... to shell?
19+
* @return {Promise<unknown>}
20+
*/
1421
export function spawnExecCmd(cmd,args=[],opts={}){
1522
const actual = {shell:true,...opts}
1623
return new Promise((resolve, reject) => {

dev/node-fs-utils-dev/SpawnCmd.test.mjs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,18 @@ function writeToFile(fileName,data,space=2){
7979
import {promisify} from 'node:util';
8080
import {spawn,spawnSync} from 'node:child_process';
8181
import {spawnExecCmd} from "##/dev/node-fs-utils-dev/SpawnCmd.mjs";
82+
import {cwd} from 'node:process';
83+
function assertEcho(actual,expected){
84+
assert.strictEqual(actual.replace(/\r/g,''),expected);
8285

86+
}
8387
describe('SpawnCmd.test.mjs', function(){
8488
it('spawnExecCmd', async function(){
8589
this.timeout(5000);
8690
let out;
8791
out = await spawnExecCmd('echo hi',[],{shell:true});
8892
// console.log(out);
89-
assert.strictEqual(out.stdout,'hi\n');
93+
assertEcho(out.stdout,'hi\n');
9094
});
9195
it('spawnSync', async function(){
9296
this.timeout(5000);
@@ -100,10 +104,17 @@ describe('SpawnCmd.test.mjs', function(){
100104
// console.log(out);
101105
//UintArrasy
102106
// const tmp = new Uint8Array(stdout);
103-
assert.strictEqual(hello,'hi\n');
107+
assertEcho(hello,'hi\n');
104108
});
109+
105110
});
111+
/**
112+
* look at
113+
* spawnCmd-cwd.test.mjs
114+
* for device specific
115+
*/
106116

117+
//
107118
describe('SpawnCmd.test.mjs experiments', function(){
108119
/**
109120
* doesnt work
@@ -116,3 +127,7 @@ describe('SpawnCmd.test.mjs experiments', function(){
116127
console.log(out);
117128
});
118129
});
130+
131+
/**
132+
* env seems to be done in vite-press-docs.git
133+
*/
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env pwsh.exe
2+
<#
3+
node
4+
pwsh.exe dev/node-fs-utils-dev/tests/dev-specific/generate-env-logs.ps1
5+
pwsh.exe dev/node-fs-utils-dev/tests/dev-specific/generate-env-logs.ps1 -NODE_FIRST_ARG "pwsh-cli"
6+
$env:NODE_FIRST_ARG="pwsh-man-cli";pwsh.exe dev/node-fs-utils-dev/tests/dev-specific/generate-env-logs.ps1
7+
#>
8+
# addd params
9+
param(
10+
[string] $NODE_FIRST_ARG="pwsh-int"
11+
)
12+
if(!$env:NODE_FIRST_ARG){
13+
$env:NODE_FIRST_ARG=$NODE_FIRST_ARG
14+
}
15+
# set NODE_FIRST_ARG=$NODE_FIRST_ARG
16+
# get current parent dir
17+
$parentDir = Split-Path -Path $MyInvocation.MyCommand.Path -Parent
18+
#
19+
write-host "$parentDir/temp/$NODE_FIRST_ARG.txt"
20+
c:/progra~1/PowerShell/7/pwsh.exe -c Get-ChildItem env: > "$parentDir/temp/$NODE_FIRST_ARG.txt"
21+
#node "$parentDir/generate-env.mjs"
22+
#which.exe node.exe
23+
node.exe -v
24+
write-host "$parentDir/generate-env.mjs"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash.exe
2+
# cd /mnt/c/Users/Jason/WebstormProjects/nuxt3-win32-posix-path
3+
# c:/cygwin64/bin/env.exe
4+
cd /mnt/c/Users/Jason/WebstormProjects/nuxt3-win32-posix-path
5+
PROOT="/mnt/c/Users/Jason/WebstormProjects/nuxt3-win32-posix-path"
6+
NODE="/mnt/c/Users/Jason/AppData/Roaming/nvm/v16.20.1/node.exe"
7+
$NODE -v
8+
pwd
9+
# get current file directory
10+
parentDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
11+
echo $parentDir
12+
echo "$parentDir/generate-env.mjs"
13+
# export NODE_FIRST_ARG="cygwin"; $NODE "$parentDir/generate-env.mjs"
14+
export NODE_PATH="/mnt/c/Users/Jason/WebstormProjects/nuxt3-win32-posix-path/node_modules/.pnpm/node_modules"
15+
export NODE_FIRST_ARG="cygwin"; $NODE "$PROOT/dev/node-fs-utils-dev/tests/dev-specific/generate-env.mjs"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env node
2+
/**
3+
* .....pnpm run dev/node-fs-utils-dev/tests/dev-specific/generate-env.mjs
4+
* assumes pwd is project root
5+
node dev/node-fs-utils-dev/tests/dev-specific/generate-env.mjs
6+
*/
7+
console.log("process.env.NODE_FIRST_ARG:",process.env.NODE_FIRST_ARG);
8+
import { log } from "node:console";
9+
import fs from "node:fs";
10+
import {dirname} from "node:path"
11+
import {fileURLToPath} from "node:url"
12+
console.log("import.meta.url:",import.meta.url);
13+
const __dirname = dirname(fileURLToPath(import.meta.url)); //Folder of current file (from file://url)
14+
function writeToFile(fileName,data,space=2){
15+
const sFileName = /\./.test(fileName) ? fileName : fileName + '.json';
16+
const filePath = `${__dirname}/temp/${sFileName}`
17+
fs.writeFileSync(filePath,
18+
typeof data === 'string' ? data :JSON.stringify(data,null,+space)
19+
);
20+
}
21+
22+
/* get first args */
23+
// const args = process.argv.slice(2);
24+
// console.log(args);
25+
// const [firstArg] = args || ["cli-env"];
26+
const firstArg = process.env.NODE_FIRST_ARG || "cli-env";
27+
28+
writeToFile(`${firstArg}.raw.json`,JSON.stringify(process.env,null,2));//this works... lol interesting

0 commit comments

Comments
 (0)