Skip to content

Commit 14d929f

Browse files
committed
fixed the exe... might want to change the order again though
1 parent b58c743 commit 14d929f

File tree

5 files changed

+183
-7
lines changed

5 files changed

+183
-7
lines changed

lib/bin_build/index.mjs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
/**
22
* Bin Build Index Packager
33
* maybe add cli builder / handler here
4+
lib/bin_build/dist/index-win.exe c:/Users/Public/Documents
5+
6+
node lib/bin_build/index.mjs c:/Users/Public/Documents
7+
node lib/bin_build/index.mjs "c:/Users/Public/Docum ents"
8+
node lib/bin_build/index.mjs c:/Users/Public/Docum ents
9+
*
10+
* todo think about how to test this properly performance wise
11+
* it's surprisingly not bad. powershell was much slower...
412
*/
5-
import Win32ToWin32WSL2 from "##/src/win32ToWin32WSL/win32ToWin32WSL2.mjs";
6-
export {Win32ToWin32WSL2}
13+
// import process from "node:process";
14+
import {win32ToWin32WSL2} from "##/src/win32ToWin32WSL/win32ToWin32WSL2.mjs";
15+
// export {win32ToWin32WSL2}
16+
17+
/* take arguments from command line */
18+
const args = process.argv.slice(2);
19+
// console.log(args);
20+
// console.log(win32ToWin32WSL2(args[0]))
21+
console.log(win32ToWin32WSL2(args.join(' ')))
22+
process.exit(0)

lib/test-utils/mocha-cli-exec.mjs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import {spawnSync} from "node:child_process";
2+
import assert from "node:assert";
3+
4+
/**
5+
* factory function
6+
*/
7+
/**
8+
*
9+
* @param pathToExe
10+
* @param args
11+
* @param options
12+
* @return {(function(*, *): void)|*}
13+
* @example
14+
* const assertW2Wb = createMochaCliExe(W2WB);1
15+
*/
16+
export function createMochaCliExe(pathToExe,args=[],options={}){
17+
//todo add better defaulting etc... didnt think i neeeded to modify the input
18+
const actualOptions = {shell:true,...options}
19+
20+
return function(expectedValue,...inputToTest){
21+
const output = spawnSync(
22+
// `"${W2WB}" [C:\\` //cmd needs to double quote
23+
// `"${pathToExe}"`,[WSLPassTests[0][0]],actualOptions
24+
`"${pathToExe}"`,[...inputToTest],actualOptions
25+
);
26+
if(output.status !== 0){
27+
console.error(output);
28+
console.log(output.stdout.toString())
29+
console.error(output.stderr.toString())
30+
throw new Error("status not 0");
31+
}
32+
const actual = output.stdout.toString().trim();
33+
console.assert(actual === expectedValue,`inputToTest: ${inputToTest}`)
34+
assert.strictEqual(actual,expectedValue);
35+
}
36+
37+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"docs:preview": "vitepress preview docs",
1818
"build-rollup:vite": "vite build --mode production",
1919
"build-rollup:pkg": "pkg lib/dist/index.js --out-path lib/dist/bins",
20+
"build-bins" : "pnpm run /build-bins:.*/",
2021
"build-bins:rollup": "vite build --mode production --config lib/bin_build/bin-vite.config.mjs",
2122
"build-bins:pkg": "pkg lib/bin_build/.output/index.js --out-path lib/bin_build/dist/"
2223
},

tests/unit/mocha-cli-exec.mjs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**
2+
yarn add mocha -D
3+
4+
package.json
5+
"imports": {
6+
"##/*": {
7+
"default": "./*"
8+
},
9+
},
10+
"type": "module",
11+
12+
jsconfig.json
13+
{
14+
"compilerOptions": {
15+
"baseUrl": ".",
16+
"paths": {
17+
"##/*": ["./*"]
18+
}
19+
},
20+
"exclude": ["node_modules", ".nuxt", "dist"]
21+
}
22+
23+
24+
25+
*/
26+
// import { createRequire } from 'module';
27+
// const require = createRequire(import.meta.url);
28+
// const assert = require('assert');
29+
// const {describe,it} = require('mocha');
30+
import assert from 'node:assert';
31+
import { describe, it} from 'mocha';
32+
/*
33+
1.
34+
yarn add mocha @babel/polyfill @babel/register @babel/preset-env babel-plugin-module-resolver --dev
35+
yarn add @babel/core --dev
36+
2.
37+
-r @babel/register -r babel-plugin-module-resolver
38+
39+
3.
40+
.babelrc
41+
{
42+
43+
"presets": ["@babel/preset-env"],
44+
"plugins": [
45+
["module-resolver", {
46+
"root": ["./src"],
47+
"alias": {
48+
"test": "./test",
49+
"underscore": "lodash",
50+
51+
"~": "./"
52+
}
53+
}]
54+
]
55+
56+
}
57+
test specific timeout
58+
this.timeout(500);//500ms
59+
*/
60+
/**
61+
* Should put this somewhere safe
62+
* todo filepath needs to be initialized as well...
63+
* @param fileName .json
64+
* @param data will automatically be changed
65+
*/
66+
import fs from 'node:fs';
67+
import {createMochaCliExe} from "##/lib/test-utils/mocha-cli-exec.mjs";
68+
function writeToFile(fileName,data,space=2){
69+
const sFileName = /\./.test(fileName) ? fileName : fileName + '.json';
70+
const filePath = `dev/pbs/test/${sFileName}`
71+
fs.writeFileSync(filePath,
72+
typeof data === 'string' ? data :JSON.stringify(data,null,+space)
73+
);
74+
}
75+
describe('tests/unit/mocha-cli-exec.mjs', function(){
76+
const assertW2bMJS = createMochaCliExe("node.exe")
77+
const pathToJS = "lib/bin_build/index.mjs"
78+
it('Check factory function - createMochaCliExe', function(){
79+
//assert.strictEqual(1,1);//require assert
80+
const fn = createMochaCliExe()
81+
console.log(fn.toString());
82+
});
83+
it('check index.mjs without spaces', function(){
84+
assertW2bMJS("/mnt/c/Users/Public/Documents",pathToJS,"c:/Users/Public/Documents");
85+
});
86+
it('check index.mjs with spaces', function(){
87+
assertW2bMJS("/mnt/c/Users/Public/Docu\\ ments",pathToJS,"c:/Users/Public/Docu ments");
88+
});
89+
});

tests/unit/win32ToWin32WSL2.test.mjs

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe('win32ToWin32WSL2.test.mjs', function(){
143143
* wsl param tests
144144
*
145145
*/
146-
const WSLPassTests = [
146+
export const WSLPassTests = [
147147
["C:\\Users\\Public\\Documents","/mnt/c/Users/Public/Documents"],//maybe append with quotes instead?
148148
["C:\\Users\\Public\\temp spaces\\a\\b c\\d","/mnt/c/Users/Public/temp\\ spaces/a/b\\ c/d"],
149149
["C:\\Users\\Public\\temp spaces\\a\\b c\\d","/mnt/c/Users/Public/temp\\ spaces/a/b\\ c/d"],
@@ -165,19 +165,52 @@ for (let i = 0; i < ogLength; i++) {
165165
* parameterized tests
166166
*/
167167
import {spawnSync} from "node:child_process";
168+
import {createMochaCliExe} from "##/lib/test-utils/mocha-cli-exec.mjs";
168169

169170
describe('WSLPassTests', function(){
171+
/** @type {string|'Win32ToWin32WSL2BinaryPath'} */
172+
const W2WB = "lib/bin_build/dist/index-win.exe";
173+
const assertW2Wb = createMochaCliExe(W2WB);
174+
/* raw */
175+
it('WSLPassTests mocha exe', function(){
176+
const output = spawnSync(
177+
// `"${W2WB}" [C:\\` //cmd needs to double quote
178+
`"${W2WB}"`,[WSLPassTests[0][0]],{shell:true}
179+
);
180+
if(output.status !== 0){
181+
console.error(output);
182+
console.log(output.stdout.toString())
183+
console.error(output.stderr.toString())
184+
throw new Error("status not 0");
185+
}
186+
const actual = output.stdout.toString().trim();
187+
assert.strictEqual(actual,WSLPassTests[0][1]);
188+
});
189+
/* wrapper note reversed */
190+
it('WSLPassTests assertW2Wb', function(){
191+
assertW2Wb(WSLPassTests[0][1],WSLPassTests[0][0]);
192+
});
193+
/* wrapper note reversed */
194+
it('WSLPassTests assertW2Wb - spaces', function(){
195+
assertW2Wb(WSLPassTests[1][1],WSLPassTests[1][0]);
196+
});
197+
/**/
170198
for (let i = 0; i < WSLPassTests.length; i++) {
171199
const [inputWinPath, expectedMntPath, wslPassTestIndex] = WSLPassTests[i];
172200
it(`WSLPassTests MJS ${wslPassTestIndex}`, function () {
173201
// console.log(wslPassTestIndex,inputWinPath);
174202
const actual = win32ToWin32WSL2(inputWinPath);
175203
assert.strictEqual(actual,expectedMntPath);
176204
});
177-
it(`WSLPassTests ps1 ${wslPassTestIndex}`, function () {
178-
// console.log(wslPassTestIndex,inputWinPath);
179-
const output = spawnSync(inputWinPath);
180-
assert.strictEqual(actual,expectedMntPath);
205+
/* scrapping ps1 / sh using exe for now */
206+
// it(`WSLPassTests ps1 ${wslPassTestIndex}`, function () {
207+
// // console.log(wslPassTestIndex,inputWinPath);
208+
// const output = spawnSync(inputWinPath);
209+
// assert.strictEqual(actual,expectedMntPath);
210+
// });
211+
it(`WSLPassTests exe ${wslPassTestIndex}`, function(){
212+
// // console.log(wslPassTestIndex,inputWinPath);
213+
assertW2Wb(expectedMntPath,[inputWinPath]);
181214
});
182215
}
183216
});

0 commit comments

Comments
 (0)