feat: 增加环境切换
This commit is contained in:
+15
-14
@@ -52,7 +52,7 @@ beforeEach(() => {
|
||||
requests = [];
|
||||
navigations = [];
|
||||
apiConfig.developmentEnvironment = 'local';
|
||||
apiConfig.onlineBaseUrl = '';
|
||||
apiConfig.productionBaseUrl = 'http://127.0.0.1:8800/api/v1';
|
||||
handler = () => ({ data: [] });
|
||||
globalThis.wx = {
|
||||
getAccountInfoSync: () => ({ miniProgram: { envVersion: 'develop' } }),
|
||||
@@ -152,22 +152,23 @@ function useRows(rows, selectedCategories = categories) {
|
||||
};
|
||||
}
|
||||
|
||||
test('环境配置:开发版默认本地,正式/体验/未知环境不回退本地,线上要求 HTTPS', () => {
|
||||
assert.equal(
|
||||
resolveApiConfig('develop').baseUrl,
|
||||
'http://127.0.0.1:8800/api/v1',
|
||||
);
|
||||
for (const version of ['release', 'trial', 'unknown'])
|
||||
assert.throws(() => resolveApiConfig(version), /线上/);
|
||||
apiConfig.onlineBaseUrl = 'https://api.example.test/api/v1/';
|
||||
for (const version of ['release', 'trial'])
|
||||
test('环境配置:体验/正式/未知包固定 production,暂允许指定的本机占位地址', () => {
|
||||
assert.equal(resolveApiConfig('develop').environment, 'local');
|
||||
for (const version of ['release', 'trial', 'unknown']) {
|
||||
assert.equal(resolveApiConfig(version).environment, 'production');
|
||||
assert.equal(
|
||||
resolveApiConfig(version).baseUrl,
|
||||
'https://api.example.test/api/v1',
|
||||
'http://127.0.0.1:8800/api/v1',
|
||||
);
|
||||
apiConfig.developmentEnvironment = 'online';
|
||||
assert.equal(resolveApiConfig('develop').environment, 'online');
|
||||
apiConfig.onlineBaseUrl = 'http://api.example.test/api/v1';
|
||||
}
|
||||
apiConfig.productionBaseUrl = '';
|
||||
assert.throws(() => resolveApiConfig('release'), /production/);
|
||||
apiConfig.productionBaseUrl = 'https://api.example.test/api/v1/';
|
||||
assert.equal(
|
||||
resolveApiConfig('release').baseUrl,
|
||||
'https://api.example.test/api/v1',
|
||||
);
|
||||
apiConfig.productionBaseUrl = 'http://api.example.test/api/v1';
|
||||
assert.throws(() => resolveApiConfig('release'), /配置/);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user