Skip to content

Commit 092eff5

Browse files
committed
:add: test files
1 parent 335f2f3 commit 092eff5

File tree

9 files changed

+165
-122
lines changed

9 files changed

+165
-122
lines changed

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
registry = https://registry.npm.taobao.org

micro-app.config.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ module.exports = {
3131
},
3232
},
3333

34-
// plugins: [
35-
// '@micro-app/plugin-webpack-adapter',
36-
// '@micro-app/plugin-vue-cli',
37-
// ],
34+
plugins: [
35+
'@micro-app/plugin-webpack-adapter',
36+
[{
37+
id: 'plugin-vue-cli',
38+
link: __dirname + '/src/index.js',
39+
}],
40+
],
3841

3942
};

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@
3939
"vue-template-compiler": "^2.0.0"
4040
},
4141
"devDependencies": {
42-
"@micro-app/cli": "^0.2.0-beta.2",
43-
"@micro-app/core": "^0.2.0-beta.2",
44-
"@micro-app/plugin-webpack-adapter": "^0.1.0-beta.2",
42+
"@micro-app/cli": "^0.2.0-beta.4",
43+
"@micro-app/core": "^0.2.0-beta.6",
44+
"@micro-app/plugin-webpack-adapter": "^0.1.0-beta.4",
4545
"@types/jest": "^24.0.18",
46-
"babel-eslint": "^10.0.3",
47-
"coveralls": "^3.0.6",
46+
"coveralls": "^3.0.7",
4847
"eslint": "^5.16.0",
4948
"eslint-config-2o3t": "^1.1.17",
5049
"jest": "^24.9.0",

src/index.test.js

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@ describe('Plugin VueCLIAdapter', () => {
88

99
it('VueCLIAdapter', () => {
1010
const { service } = require('@micro-app/cli/bin/base');
11-
service.registerPlugin({
12-
id: '@micro-app/plugin-webpack-adapter',
13-
});
14-
service.registerPlugin({
15-
id: 'test:VueCLIAdapter',
16-
link: path.join(__dirname, './index.js'),
17-
});
11+
// service.registerPlugin({
12+
// id: '@micro-app/plugin-webpack-adapter',
13+
// });
14+
// service.registerPlugin({
15+
// id: 'test:VueCLIAdapter',
16+
// link: path.join(__dirname, './index.js'),
17+
// });
1818

1919
service.run('help', { _: [] });
2020
});
2121

2222
it('resolveWebpackConfig', () => {
2323
const { service } = require('@micro-app/cli/bin/base');
24-
service.registerPlugin({
25-
id: '@micro-app/plugin-webpack-adapter',
26-
});
27-
service.registerPlugin({
28-
id: 'test:VueCLIAdapter',
29-
link: path.join(__dirname, './index.js'),
30-
});
24+
// service.registerPlugin({
25+
// id: '@micro-app/plugin-webpack-adapter',
26+
// });
27+
// service.registerPlugin({
28+
// id: 'test:VueCLIAdapter',
29+
// link: path.join(__dirname, './index.js'),
30+
// });
3131
service.registerPlugin({
3232
id: 'test:print',
3333
apply(api) {
@@ -44,41 +44,41 @@ describe('Plugin VueCLIAdapter', () => {
4444

4545
it('vue:serve', () => {
4646
const { service } = require('@micro-app/cli/bin/base');
47-
service.registerPlugin({
48-
id: '@micro-app/plugin-webpack-adapter',
49-
});
50-
service.registerPlugin({
51-
id: 'test:VueCLIAdapter',
52-
link: path.join(__dirname, './index.js'),
53-
});
47+
// service.registerPlugin({
48+
// id: '@micro-app/plugin-webpack-adapter',
49+
// });
50+
// service.registerPlugin({
51+
// id: 'test:VueCLIAdapter',
52+
// link: path.join(__dirname, './index.js'),
53+
// });
5454

5555
// service.run('vue-service-serve', { _: [] });
5656
service.run('help', { _: [ 'vue-service-serve' ] });
5757
});
5858

5959
it('vue:build', () => {
6060
const { service } = require('@micro-app/cli/bin/base');
61-
service.registerPlugin({
62-
id: '@micro-app/plugin-webpack-adapter',
63-
});
64-
service.registerPlugin({
65-
id: 'test:VueCLIAdapter',
66-
link: path.join(__dirname, './index.js'),
67-
});
61+
// service.registerPlugin({
62+
// id: '@micro-app/plugin-webpack-adapter',
63+
// });
64+
// service.registerPlugin({
65+
// id: 'test:VueCLIAdapter',
66+
// link: path.join(__dirname, './index.js'),
67+
// });
6868

6969
// service.run('vue-service-build', { _: [] });
7070
service.run('help', { _: [ 'vue-service-build' ] });
7171
});
7272

7373
it('vue:inspect', () => {
7474
const { service } = require('@micro-app/cli/bin/base');
75-
service.registerPlugin({
76-
id: '@micro-app/plugin-webpack-adapter',
77-
});
78-
service.registerPlugin({
79-
id: 'test:VueCLIAdapter',
80-
link: path.join(__dirname, './index.js'),
81-
});
75+
// service.registerPlugin({
76+
// id: '@micro-app/plugin-webpack-adapter',
77+
// });
78+
// service.registerPlugin({
79+
// id: 'test:VueCLIAdapter',
80+
// link: path.join(__dirname, './index.js'),
81+
// });
8282

8383
service.run('vue-service-inspect', { _: [] });
8484
});

src/methods.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = function Methods(api, projectOptions) {
99
// 针对 vue plugin 的注册
1010
api.extendMethod('registerVuePlugin', {
1111
description: '针对 vue-cli plugin 的注册方法.',
12-
}, options => {
12+
}, function(options) {
1313
const { id, opts = {}, link, apply } = options;
1414
assert(id, 'id must supplied');
1515
assert(typeof id === 'string', 'id must be string');
@@ -32,19 +32,19 @@ module.exports = function Methods(api, projectOptions) {
3232

3333
api.extendMethod('registerVueCommand', {
3434
description: '针对 vue-cli command 的注册方法.',
35-
}, (name, opts, fn) => {
35+
}, function(name, opts, fn) {
3636
assert(name, 'name must supplied');
3737
assert(typeof name === 'string', 'name must be string');
38+
let tempFn = fn;
3839
switch (name) {
3940
case 'serve': {
40-
const tempFn = fn;
41-
fn = async function(args) {
41+
tempFn = async function(args) {
4242
// beforeDevServer
4343
api.applyPluginHooks('beforeDevServer', { args });
4444

45-
if (tempFn) {
45+
if (fn) {
4646
try {
47-
await tempFn(args);
47+
await fn.call(this, args);
4848
} catch (err) {
4949
api.logger.error(err);
5050
api.applyPluginHooks('afterDevServer', { args, err });
@@ -58,14 +58,13 @@ module.exports = function Methods(api, projectOptions) {
5858
break;
5959
}
6060
case 'build': {
61-
const tempFn = fn;
62-
fn = async function(args) {
61+
tempFn = async function(args) {
6362
// beforeBuild
6463
api.applyPluginHooks('beforeBuild', { args });
6564

66-
if (tempFn) {
65+
if (fn) {
6766
try {
68-
await tempFn(args);
67+
await fn.call(this, args);
6968
api.applyPluginHooks('onBuildSuccess', { args });
7069
} catch (err) {
7170
api.logger.error(err);
@@ -82,7 +81,7 @@ module.exports = function Methods(api, projectOptions) {
8281
default:
8382
break;
8483
}
85-
api.registerCommand(`vue-service-${name}`, opts, fn);
84+
api.registerCommand(`vue-service-${name}`, opts, tempFn);
8685
});
8786

8887
};

src/plugins/commandPlugins.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@ const path = require('path');
44

55
module.exports = function CommandPlugins(api, vueRoot, projectOptions) {
66

7-
[
7+
return [
88
'serve',
99
'build',
1010
'inspect',
11-
]
12-
.forEach(name => {
13-
14-
// register
15-
api.registerVuePlugin({
16-
id: `vue-service:plugins-command-${name}`,
17-
link: require.resolve(path.resolve(vueRoot, 'commands', name)),
18-
description: `[vue-service] command - ${name}`,
19-
});
11+
].forEach(name => {
2012

13+
// register
14+
api.registerVuePlugin({
15+
id: `vue-service:plugins-command-${name}`,
16+
link: require.resolve(path.resolve(vueRoot, 'commands', name)),
17+
description: `[vue-service] command - ${name}`,
2118
});
19+
20+
});
2221
};

src/plugins/configPlugins.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ module.exports = function ConfigPlugins(api, vueRoot, projectOptions) {
99
'css',
1010
'prod',
1111
'app',
12-
]
13-
.forEach(name => {
12+
].forEach(name => {
1413
// register
15-
api.registerVuePlugin({
16-
id: `vue-service:plugins-config-${name}`,
17-
link: path.resolve(vueRoot, 'config', name),
18-
description: `[vue-service] config - ${name}`,
19-
});
14+
api.registerVuePlugin({
15+
id: `vue-service:plugins-config-${name}`,
16+
link: path.resolve(vueRoot, 'config', name),
17+
description: `[vue-service] config - ${name}`,
2018
});
19+
});
2120

2221
};

test/index.test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
/* global expect */
4+
5+
describe('Plugin VueCLI bin', () => {
6+
7+
it('vue:serve run', async () => {
8+
const shelljs = require('shelljs');
9+
10+
const { code, stderr } = shelljs.exec('node bin/micro-app-vue.js serve', {
11+
cwd: process.cwd(),
12+
timeout: 3000,
13+
});
14+
15+
if (code && stderr) {
16+
throw new Error(stderr);
17+
}
18+
});
19+
20+
it('vue:build run', () => {
21+
const shelljs = require('shelljs');
22+
23+
const { code, stderr } = shelljs.exec('node bin/micro-app-vue.js build', {
24+
cwd: process.cwd(),
25+
timeout: 3000,
26+
});
27+
28+
if (code && stderr) {
29+
throw new Error(stderr);
30+
}
31+
});
32+
33+
});

0 commit comments

Comments
 (0)