63 lines
1.9 KiB
JavaScript
63 lines
1.9 KiB
JavaScript
|
|
const assert = require('assert');
|
|||
|
|
const {
|
|||
|
|
getDefaultAppIdentifier,
|
|||
|
|
getDefaultJavaGit,
|
|||
|
|
getProjectBaseName,
|
|||
|
|
getRepositoryName,
|
|||
|
|
updateConfigSource,
|
|||
|
|
validateProjectName,
|
|||
|
|
} = require('../src/create');
|
|||
|
|
|
|||
|
|
assert.strictEqual(
|
|||
|
|
getProjectBaseName('zcloud_gbs_basic_info_gwj-react'),
|
|||
|
|
'zcloud_gbs_basic_info_gwj'
|
|||
|
|
);
|
|||
|
|
assert.strictEqual(getProjectBaseName('custom-project'), 'custom-project');
|
|||
|
|
assert.match(
|
|||
|
|
getDefaultJavaGit('zcloud_gbs_basic_info_gwj-react'),
|
|||
|
|
/\/zcloud_gbs\/zcloud_gbs_basic_info_gwj\.git$/
|
|||
|
|
);
|
|||
|
|
assert.strictEqual(
|
|||
|
|
getRepositoryName('https://example.com/group/custom-server.git'),
|
|||
|
|
'custom-server'
|
|||
|
|
);
|
|||
|
|
assert.strictEqual(
|
|||
|
|
getDefaultAppIdentifier(
|
|||
|
|
'https://example.com/group/zcloud_gbs_enterprise_user_gwj.git'
|
|||
|
|
),
|
|||
|
|
'enterpriseUser'
|
|||
|
|
);
|
|||
|
|
assert.strictEqual(
|
|||
|
|
getDefaultAppIdentifier('https://example.com/group/zcloud_gbs_aqd.git'),
|
|||
|
|
'aqd'
|
|||
|
|
);
|
|||
|
|
assert.strictEqual(validateProjectName('demo-react'), 'demo-react');
|
|||
|
|
assert.throws(() => validateProjectName('../demo'), /非法字符/);
|
|||
|
|
|
|||
|
|
const configSource = `module.exports = {
|
|||
|
|
javaGit: "<git-url>",
|
|||
|
|
javaGitName: "<git-name>",
|
|||
|
|
environment: {
|
|||
|
|
development: {
|
|||
|
|
javaGitBranch: "<branch-name>",
|
|||
|
|
},
|
|||
|
|
production: {
|
|||
|
|
javaGitBranch: "<branch-name>",
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
appIdentifier: "唯一应用标识,与后端gateway相同",
|
|||
|
|
};
|
|||
|
|
`;
|
|||
|
|
const updatedConfig = updateConfigSource(configSource, {
|
|||
|
|
javaGit: 'https://example.com/group/zcloud_gbs_basic_info_gwj.git',
|
|||
|
|
javaGitName: 'customJavaRepository',
|
|||
|
|
appIdentifier: 'customApp',
|
|||
|
|
productionBranch: 'release',
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
assert.match(updatedConfig, /javaGit: "https:\/\/example\.com\/group\/zcloud_gbs_basic_info_gwj\.git"/);
|
|||
|
|
assert.match(updatedConfig, /javaGitName: "customJavaRepository"/);
|
|||
|
|
assert.match(updatedConfig, /appIdentifier: "customApp"/);
|
|||
|
|
assert.match(updatedConfig, /development: \{\s+javaGitBranch: "<branch-name>"/);
|
|||
|
|
assert.match(updatedConfig, /production: \{\s+javaGitBranch: "release"/);
|