diff --git a/src/index.test.js b/src/index.test.js new file mode 100644 index 0000000..e655888 --- /dev/null +++ b/src/index.test.js @@ -0,0 +1,26 @@ +const assert = require('node:assert/strict'); +const { spawnSync } = require('node:child_process'); +const path = require('node:path'); +const test = require('node:test'); + +test('主流程失敗時會輸出階段前綴與錯誤碼', () => { + const result = spawnSync( + process.execPath, + [path.join(__dirname, 'index.js')], + { + cwd: path.join(__dirname, '..'), + env: { + ...process.env, + GITEA_SERVER_URL: '', + GITEA_REPOSITORY: 'owner/repo', + RUNNER_TOKEN: 'token', + IS_BETA: 'false', + }, + encoding: 'utf8', + }, + ); + + assert.equal(result.status, 1); + assert.match(result.stderr, /^\[參數檢查\]\[ERR\]\[\d{4}\/\d{2}\/\d{2} /); + assert.match(result.stderr, /GITEA_SERVER_URL 未設定/); +});