Files
self/app/scripts/tests/cleanupIosBuild.test.cjs
Justin Hernandez 20fa5c5adc [SELF-700] feat: add mock document generator demo (#995)
* feat: add mock document generator demo

* feat: add mock document generator

* fixes

* chore: refresh workflow cache

* update lock

* build

* updates

* more fixes

* code rabbit feedback

* compiles

* save wip

* updates

* merge with dev and fixes

* fix: align hoisting and demo Jest resolver (#1003)

* chore(app): map common src paths and declare svg flag module

* ci fix

* update lock

* save wip

* chore: address yarn lock issues (#1004)

* address yarn lock issues

* fix postinstall

* fix ci

* use metro js proxy

* android build working for /app

* save wip

* fix merge

* pipeline fixes

* format

* fix pipelines

* bump limit and split

* fix pipeline issues

* chore: decouple demo app build (#1013)

* chore: decouple demo app build

* chore: move demo app to workspace

* chore: unpublish demo workspace

* fix mobile sdk tests

* updates

* remove polyfills

* update merge

* update resolutions

* update resolutions

* fix merge

* fix paths

* save wip

* save wip fixes rd2

* working android

* update lock

* save wip ios building

* fix merge

* readd public key

* fixes

* ci fixes

* fixes

* fix web building

* fix ci

* fix tests

* update lock

* fix ci rd2

* formatting and fix ci

* fix

* finalize ci fixes

* fix tests and metro config paths for building

* save wip

* install missing package for pipeline

* fix wip app building

* wip react config

* save working emulator compile

* first round of pr fixes and feedback

* clean up demo app artifacts from sdk

* Add Gradle wrapper files for mobile-sdk-demo Android build

- Added gradlew, gradlew.bat, and gradle/wrapper/ directory
- Updated .gitignore to allow committing Gradle wrapper files
- Fixes Android build error: spawn ./gradlew ENOENT

* codex feedback and fixes

* fix tests

* file renames

* revert back to dev

* add types

* coderabbit fixes

* fix tests

* fix tests

* fix test

* fixes

* fix wip coderabbit issues

* coderabbit suggestions rd 2

* fix ci pipelines and addresss warnings

* cr fixes

* convert kebab to camelCase

* save wip fixes

* update reinstall and lock files

* fixes

* remove file

* fix lint

* fix polyfill fallback issues

* ensure that mock document is not on ofac list

* prettier
2025-09-27 13:59:47 -07:00

93 lines
3.1 KiB
JavaScript

// SPDX-FileCopyrightText: 2025 Social Connect Labs, Inc.
// SPDX-License-Identifier: BUSL-1.1
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
const { mkdtempSync, mkdirSync, writeFileSync, readFileSync } = require('fs');
const { join, resolve } = 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 = resolve(__dirname, '../cleanup-ios-build.sh');
describe('cleanup-ios-build.sh', () => {
it('resets pbxproj and reapplies versions', () => {
const tmp = mkdtempSync(join(os.tmpdir(), 'cleanup-test-'));
const projectName = 'MyApp';
const iosDir = join(tmp, 'ios', `${projectName}.xcodeproj`);
mkdirSync(iosDir, { recursive: true });
const pbxPath = join(iosDir, 'project.pbxproj');
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');
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 = 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 = mkdtempSync(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 = mkdtempSync(join(os.tmpdir(), 'cleanup-test-'));
const projectName = 'BadApp';
const iosDir = join(tmp, 'ios', `${projectName}.xcodeproj`);
mkdirSync(iosDir, { recursive: true });
const pbxPath = join(iosDir, 'project.pbxproj');
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'));
});
});