mirror of
https://github.com/selfxyz/self.git
synced 2026-04-05 03:00:53 -04:00
* feat: improve deployment tooling * cr feedback * for temp testing * clean build artifacts after deploy * add deploy source * uncomment ios commands * Add tests for minor deployment fixes (#750) * Add test coverage for deployment scripts and Fastfile * format * increase github check to 5 minutes
89 lines
2.9 KiB
JavaScript
89 lines
2.9 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
const os = require('os');
|
|
const { execSync } = require('child_process');
|
|
const { spawnSync } = require('child_process');
|
|
const { describe, it } = require('node:test');
|
|
const assert = require('node:assert');
|
|
|
|
const SCRIPT = path.resolve(__dirname, '../cleanup-ios-build.sh');
|
|
|
|
describe('cleanup-ios-build.sh', () => {
|
|
it('resets pbxproj and reapplies versions', () => {
|
|
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'cleanup-test-'));
|
|
const projectName = 'MyApp';
|
|
const iosDir = path.join(tmp, 'ios', `${projectName}.xcodeproj`);
|
|
fs.mkdirSync(iosDir, { recursive: true });
|
|
const pbxPath = path.join(iosDir, 'project.pbxproj');
|
|
fs.writeFileSync(
|
|
pbxPath,
|
|
'CURRENT_PROJECT_VERSION = 1;\nMARKETING_VERSION = 1.0.0;\n',
|
|
);
|
|
|
|
const cwd = process.cwd();
|
|
process.chdir(tmp);
|
|
execSync('git init -q');
|
|
execSync('git config user.email "test@example.com"');
|
|
execSync('git config user.name "Test"');
|
|
execSync(`git add ${pbxPath}`);
|
|
execSync('git commit -m init -q');
|
|
|
|
fs.writeFileSync(
|
|
pbxPath,
|
|
'CURRENT_PROJECT_VERSION = 2;\nMARKETING_VERSION = 2.0.0;\nSomeArtifact = 123;\n',
|
|
);
|
|
|
|
execSync(`IOS_PROJECT_NAME=${projectName} bash ${SCRIPT}`);
|
|
process.chdir(cwd);
|
|
|
|
const result = fs.readFileSync(pbxPath, 'utf8');
|
|
assert(result.includes('CURRENT_PROJECT_VERSION = 2;'));
|
|
assert(result.includes('MARKETING_VERSION = 2.0.0;'));
|
|
assert(!result.includes('SomeArtifact'));
|
|
});
|
|
|
|
it('fails when the pbxproj file does not exist', () => {
|
|
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'cleanup-test-'));
|
|
|
|
const result = spawnSync('bash', [SCRIPT], {
|
|
cwd: tmp,
|
|
env: { ...process.env, IOS_PROJECT_NAME: 'MissingProject' },
|
|
encoding: 'utf8',
|
|
});
|
|
|
|
assert.notStrictEqual(result.status, 0);
|
|
assert(result.stderr.includes('Project file not found'));
|
|
});
|
|
|
|
it('fails when version information cannot be extracted', () => {
|
|
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'cleanup-test-'));
|
|
const projectName = 'BadApp';
|
|
const iosDir = path.join(tmp, 'ios', `${projectName}.xcodeproj`);
|
|
fs.mkdirSync(iosDir, { recursive: true });
|
|
const pbxPath = path.join(iosDir, 'project.pbxproj');
|
|
fs.writeFileSync(
|
|
pbxPath,
|
|
'CURRENT_PROJECT_VERSION = ;\nMARKETING_VERSION = ;\n',
|
|
);
|
|
|
|
const cwd = process.cwd();
|
|
process.chdir(tmp);
|
|
execSync('git init -q');
|
|
execSync('git config user.email "test@example.com"');
|
|
execSync('git config user.name "Test"');
|
|
execSync(`git add ${pbxPath}`);
|
|
execSync('git commit -m init -q');
|
|
|
|
const result = spawnSync('bash', [SCRIPT], {
|
|
cwd: tmp,
|
|
env: { ...process.env, IOS_PROJECT_NAME: projectName },
|
|
encoding: 'utf8',
|
|
});
|
|
|
|
process.chdir(cwd);
|
|
|
|
assert.notStrictEqual(result.status, 0);
|
|
assert(result.stderr.includes('Failed to extract version information'));
|
|
});
|
|
});
|