Skip to content

Commit

Permalink
feat: add test but no test
Browse files Browse the repository at this point in the history
  • Loading branch information
afeiship committed May 11, 2022
1 parent 0e69228 commit f698bc6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ Rakefile
.editorconfig
.release-it.json
.prettierrc
jest.config.js
17 changes: 17 additions & 0 deletions __tests__/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const fs = require('fs');

test('change ', () => {
// todo: how to test this cli program?
const res = require('../bin');
process.stdin.emit('keypress', '', { name: 'enter' });
// process.stdin.emit('keypress', '', { name: 'enter' });
// process.stdin.on('readable', function () {
// var chunk = process.stdin.read(); // 获取到输入的信息
// console.log('chunk:', chunk);
// process.stdin.emit('end'); // 触发end事件
// });
// ks.sendKeys([' ','-', 'b', 'enter']);
// console.warn('res:', console.log.mock.calls);
// console.log(process.env);
process.stdin.emit('end');
});
10 changes: 6 additions & 4 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require('@jswork/next-absolute-package');

const { version } = nx.absolutePackage();
const program = new Command();
const exec = require('child_process').execSync;
const globby = require('globby');
const ipt = require('ipt');
const path = require('path');
Expand All @@ -32,14 +31,17 @@ nx.declare({
methods: {
start() {
if (program.boot) return this.boot();
const files = globby.sync(gpt, gopts);
const parsed = files.map((file) => path.parse(file).name);
ipt(parsed, opts).then((file) => {
const names = this.names();
ipt(names, opts).then((file) => {
const cmd = `export KUBECONFIG=${KUBE_HOME}/${file}`;
fs.writeFileSync(KUBE_BOOT, cmd, { flag: 'w' });
console.log(`🥬 ENV: '${file}' has been set!`);
});
},
names() {
const files = globby.sync(gpt, gopts);
return files.map((file) => path.parse(file).name);
},
boot() {
if (fs.existsSync(KUBE_BOOT)) return console.log(`File: ${KUBE_BOOT} existes, ignore.`);
fs.writeFileSync(KUBE_BOOT, '', { flag: 'w' });
Expand Down
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
verbose: true
};
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"kube-config-list": "bin/index.js"
},
"scripts": {
"test": "jest",
"build": "gulp",
"release": "release-it"
},
Expand All @@ -32,6 +33,7 @@
"gulp": "^4.0.2",
"gulp-load-plugins": "^2.0.5",
"gulp-replace": "^1.0.0",
"jest": "^28.1.0",
"prettier": "^2.1.2",
"release-it": "^14.2.1"
},
Expand Down

0 comments on commit f698bc6

Please sign in to comment.