mirror of
https://github.com/msojocs/wx-compiler.git
synced 2025-07-19 00:00:04 +08:00
feat: 测试用例
This commit is contained in:
parent
a317fc740c
commit
8e9a6a0490
7
.gitignore
vendored
7
.gitignore
vendored
@ -1,3 +1,8 @@
|
||||
build
|
||||
test/*.json
|
||||
wcc.exe.c
|
||||
wcc.exe.c
|
||||
|
||||
node_modules
|
||||
*output.json
|
||||
*err.js
|
||||
*stderr.json
|
9
.mocharc.js
Normal file
9
.mocharc.js
Normal file
@ -0,0 +1,9 @@
|
||||
module.exports = {
|
||||
require: [
|
||||
"@babel/register",
|
||||
'ts-node/register'
|
||||
],
|
||||
recursive: true,
|
||||
spec: "test/**/*.spec.ts",
|
||||
timeout: 20000,
|
||||
}
|
24
package.json
Normal file
24
package.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "wx-compiler",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "mocha --reporter-option maxDiffSize=1e9",
|
||||
"start": "nw ./test/node-modules"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.18.10",
|
||||
"@babel/core": "^7.18.13",
|
||||
"@babel/preset-env": "^7.18.10",
|
||||
"@babel/register": "^7.18.9",
|
||||
"@types/mocha": "^10.0.1",
|
||||
"@types/node": "^20.4.5",
|
||||
"assert": "^2.0.0",
|
||||
"mocha": "^10.0.0",
|
||||
"ts-node": "^10.9.1"
|
||||
}
|
||||
}
|
2458
pnpm-lock.yaml
generated
Normal file
2458
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
92
test/runner/node.ts
Normal file
92
test/runner/node.ts
Normal file
@ -0,0 +1,92 @@
|
||||
import { spawn } from "child_process";
|
||||
import path from "path";
|
||||
import * as fs from 'fs'
|
||||
|
||||
const wcsc = (args: string[], projectPath: string, outputPath: string | undefined = undefined) => {
|
||||
if(!fs.existsSync(projectPath)){
|
||||
throw new Error('projectPath not exists.')
|
||||
}
|
||||
const node_exec = spawn(
|
||||
path.resolve(__dirname, "../../build/wcsc"),
|
||||
args,
|
||||
{
|
||||
cwd: projectPath,
|
||||
env: {
|
||||
WX_DEBUG_COMPILER_OUTPUT: outputPath,
|
||||
},
|
||||
// stdio: 'inherit'
|
||||
}
|
||||
);
|
||||
const spwanData: any[] = [],
|
||||
errData: any[] = [];
|
||||
node_exec.stdout.on("data", (e) => {
|
||||
spwanData.push(e);
|
||||
// console.log(e.toString())
|
||||
});
|
||||
node_exec.stderr.on("data", (e) => {
|
||||
errData.push(e);
|
||||
// console.log(e.toString())
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
node_exec.on("close", (n) => {
|
||||
outputPath && require('fs').writeFileSync(`${outputPath}/linux_err.js`, Buffer.concat(errData).toString())
|
||||
|
||||
if (0 === n) {
|
||||
let result = Buffer.concat(spwanData).toString();
|
||||
// result = JSON.parse(result);
|
||||
resolve(result);
|
||||
} else {
|
||||
// process.stderr.write(Buffer.concat(errData).toString());
|
||||
// process.stderr.write(Buffer.concat(spwanData).toString());
|
||||
reject(n);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
const wcc = (args: string[], projectPath: string, outputPath: string | undefined = undefined): Promise<string> => {
|
||||
if(!fs.existsSync(projectPath)){
|
||||
throw new Error('projectPath not exists.')
|
||||
}
|
||||
const node_exec = spawn(
|
||||
path.resolve(__dirname, "../../build/wcc"),
|
||||
args,
|
||||
{
|
||||
cwd: projectPath,
|
||||
env: {
|
||||
WX_DEBUG_COMPILER_OUTPUT: outputPath,
|
||||
},
|
||||
// stdio: 'inherit'
|
||||
}
|
||||
);
|
||||
const spwanData: any[] = [],
|
||||
errData: any[] = [];
|
||||
node_exec.stdout.on("data", (e) => {
|
||||
spwanData.push(e);
|
||||
// console.log(e.toString())
|
||||
});
|
||||
node_exec.stderr.on("data", (e) => {
|
||||
errData.push(e);
|
||||
// console.log(e.toString())
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
node_exec.on("close", (n) => {
|
||||
// console.log("node n: ", n);
|
||||
outputPath && require('fs').writeFileSync(`${outputPath}/linux_err.js`, Buffer.concat(errData).toString())
|
||||
if (0 === n) {
|
||||
let result = Buffer.concat(spwanData).toString();
|
||||
// process.stdout.write(result);
|
||||
// result = JSON.parse(result);
|
||||
resolve(result);
|
||||
} else {
|
||||
process.stderr.write(Buffer.concat(errData).toString());
|
||||
// process.stderr.write(Buffer.concat(spwanData).toString());
|
||||
reject(n);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export default {
|
||||
wcsc,
|
||||
wcc
|
||||
}
|
84
test/runner/wine.ts
Normal file
84
test/runner/wine.ts
Normal file
@ -0,0 +1,84 @@
|
||||
import { spawn } from "child_process";
|
||||
import path from "path";
|
||||
import * as fs from 'fs'
|
||||
|
||||
|
||||
const wcsc = (args: string[], projectPath: string): Promise<string> => {
|
||||
if(!fs.existsSync(projectPath)){
|
||||
throw new Error('projectPath not exists.')
|
||||
}
|
||||
const wine = spawn(
|
||||
path.resolve(__dirname, "../wine/wcsc.exe"),
|
||||
args,
|
||||
{
|
||||
cwd: projectPath,
|
||||
}
|
||||
);
|
||||
const spwanData: any[] = [],
|
||||
errData: any[] = [];
|
||||
wine.stdout.on("data", (e) => {
|
||||
spwanData.push(e);
|
||||
});
|
||||
wine.stderr.on("data", (e) => {
|
||||
errData.push(e);
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
wine.on("close", (n) => {
|
||||
// console.log("wine n: ", n);
|
||||
if (0 === n) {
|
||||
let result = Buffer.concat(spwanData).toString();
|
||||
// result = JSON.parse(result);
|
||||
resolve(result);
|
||||
} else {
|
||||
process.stderr.write(
|
||||
"wine error:" +
|
||||
Buffer.concat(errData).toString()
|
||||
);
|
||||
// process.stderr.write(Buffer.concat(spwanData).toString());
|
||||
reject(n);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
const wcc = (args: string[], projectPath: string): Promise<string> => {
|
||||
if(!fs.existsSync(projectPath)){
|
||||
throw new Error('projectPath not exists.')
|
||||
}
|
||||
const wine = spawn(
|
||||
path.resolve(__dirname, "../wine/wcc.exe"),
|
||||
args,
|
||||
{
|
||||
cwd: projectPath,
|
||||
}
|
||||
);
|
||||
const spwanData: any[] = [],
|
||||
errData: any[] = [];
|
||||
wine.stdout.on("data", (e) => {
|
||||
spwanData.push(e);
|
||||
});
|
||||
wine.stderr.on("data", (e) => {
|
||||
errData.push(e);
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
wine.on("close", (n) => {
|
||||
// console.log("wine n: ", n);
|
||||
if (0 === n) {
|
||||
let result = Buffer.concat(spwanData).toString();
|
||||
// result = JSON.parse(result);
|
||||
resolve(result);
|
||||
} else {
|
||||
process.stderr.write(
|
||||
"wine error:" +
|
||||
Buffer.concat(errData).toString()
|
||||
);
|
||||
// process.stderr.write(Buffer.concat(spwanData).toString());
|
||||
reject(n);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export default {
|
||||
wcsc,
|
||||
wcc
|
||||
}
|
8
test/spec/demo.spec.ts
Normal file
8
test/spec/demo.spec.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import assert from "assert";
|
||||
import { describe } from "mocha";
|
||||
|
||||
describe('Demo', () => {
|
||||
it('should return -1 when the value is not present', function() {
|
||||
assert.equal(-1, [1,2,3].indexOf(4));
|
||||
});
|
||||
})
|
443
test/spec/wcc/lla/lla.spec.ts
Normal file
443
test/spec/wcc/lla/lla.spec.ts
Normal file
File diff suppressed because one or more lines are too long
BIN
test/wine/wcc.exe
Executable file
BIN
test/wine/wcc.exe
Executable file
Binary file not shown.
BIN
test/wine/wcsc.exe
Executable file
BIN
test/wine/wcsc.exe
Executable file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user