diff --git a/.mocharc.js b/.mocharc.js index ab96a00..cf1fcd1 100644 --- a/.mocharc.js +++ b/.mocharc.js @@ -1,6 +1,6 @@ module.exports = { require: ["@babel/register"], recursive: true, - spec: "test/**/llw.test.js", + spec: "test/**/*.test.js", timeout: 20000, } \ No newline at end of file diff --git a/test/node-modules/cases/wcc.test.js b/test/node-modules/cases/wcc.test.js new file mode 100644 index 0000000..e6ffacc --- /dev/null +++ b/test/node-modules/cases/wcc.test.js @@ -0,0 +1,51 @@ +const assert = require("assert"); +const ASTHelper = require("../../runner/ast-helper"); +const path = require("path"); +const fs = require("fs"); +const COMPILER = require('../wcc_node/lib/index') + +const originDE = assert.deepEqual +assert.deepEqual = function(){ + // console.log(arguments[0]) + try { + originDE.apply(this, arguments) + } catch (error) { + console.log('\t默认deepEqual检测失败,尝试检测语法') + const dw = ASTHelper.code2ast(JSON.stringify(arguments[0])) + const dn = ASTHelper.code2ast(JSON.stringify(arguments[1])) + originDE(dw, dn); + } +} + +describe("wcc - lla", function () { + describe("lla: node output should deep equal with wine", function () { + it("case1", async function () { + const casePath = path.resolve(__dirname, './wcc/case1') + const configPath = path.resolve(__dirname, './wcc/case1/config.json') + const projectPath = path.resolve( + __dirname, + "../../examples/miniprogram-demo/miniprogram" + ); + const storagePath = path.resolve( + __dirname, + `wcc/case1/output` + ); + const config = JSON.parse(fs.readFileSync(configPath).toString()); + config.cwd = path.join(configPath, config.cwd) + try { + fs.mkdirSync(storagePath, { recursive: true }); + } catch (error) {} + + let nodeResult = await COMPILER.wcc(config); + nodeResult = nodeResult.substring(0, nodeResult.length - 1) + + const wineResult = fs.readFileSync(`${casePath}/output/wcc_node_wine.js`) + fs.writeFileSync( + `${storagePath}/node-output.js`, + nodeResult + ); + assert.equal(wineResult, nodeResult); + }); + + }); +}); \ No newline at end of file diff --git a/test/node-modules/cases/wcc/case1/config.json b/test/node-modules/cases/wcc/case1/config.json index 000c20a..d965728 100644 --- a/test/node-modules/cases/wcc/case1/config.json +++ b/test/node-modules/cases/wcc/case1/config.json @@ -9,6 +9,6 @@ "replaceContent": { "./packageComponent/pages/camera-scan-code/camera-scan-code.wxml": "\n\n\n\n