Skip to content

Commit

Permalink
fix(plugin-define): add unit test of "should replace only in option's…
Browse files Browse the repository at this point in the history
… own property"
  • Loading branch information
deepfunc committed Oct 10, 2019
1 parent b82f361 commit 66c9454
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
4 changes: 3 additions & 1 deletion packages/plugin-define/test/fixtures/expected/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ module.exports = {
objectTest: 'development',

typeofTest: 'undefined',
typeofTest2: 'undefined'
typeofTest2: 'undefined',

builtinFuncValue: 666
};
49 changes: 31 additions & 18 deletions packages/plugin-define/test/fixtures/src/app.wpy
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@
<script lang="js">
function definedVariable () {
let BASE_URL = 'http://www.foo.com';
return BASE_URL;
}
function definedVariable() {
let BASE_URL = 'http://www.foo.com';
return BASE_URL;
}

const inObjectProperty = {
BASE_URL: 'http://foo.com'
};
const inString = 'BASE_URL';
const inObjectProperty = {
BASE_URL: 'http://foo.com'
};
const inString = 'BASE_URL';

function useBuiltinFunc() {
let obj = {};
let b = 1;

module.exports = {
definedVariable: definedVariable(),
inObjectProperty,
inString,
inTemplateLiterals: `${BASE_URL}/api/`,
__defineSetter__.call(obj, 'a', function (val) {
b = val;
});
obj.a = 666;

shouldReplaced: BASE_URL,
return b;
}

objectTest: process.env.NODE_ENV,
module.exports = {
definedVariable: definedVariable(),
inObjectProperty,
inString,
inTemplateLiterals: `${BASE_URL}/api/`,

typeofTest: typeof window,
typeofTest2: typeof(window)
}
shouldReplaced: BASE_URL,

objectTest: process.env.NODE_ENV,

typeofTest: typeof window,
typeofTest2: typeof (window),

builtinFuncValue: useBuiltinFunc()
};

</script>
8 changes: 3 additions & 5 deletions packages/plugin-define/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@ const { exec } = require('child_process');
const expect = require('chai').expect;

describe('plugin-define', function () {

it('test plugin-define', function (done) {

let wepyPath = path.resolve(process.cwd(), '../cli/bin/wepy.js');

exec(`cd test/fixtures && node ${wepyPath} build`, function (error, stdout, stderr) {
if (error) {
throw error;
}
expect(require('./fixtures/weapp/app.js'))
.to.deep.equal(require('./fixtures/expected/app.js'))

expect(require('./fixtures/weapp/app.js'))
.to.deep.equal(require('./fixtures/expected/app.js'));
done();
});
});
})
});

0 comments on commit 66c9454

Please sign in to comment.