codeplay-common 4.11.38 → 4.11.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/RELEASE_NOTES.md +13 -13
- package/files/buildCodeplay/add-splash-screen.js +1 -1
- package/files/buildCodeplay/codeplayBeforeBuild.js +2 -2
- package/files/buildCodeplay/ensure-current-build.cjs +32 -4
- package/files/buildCodeplay/fix-optimize-builld/android-r8-rules.cjs +31 -31
- package/files/buildCodeplay/fix-optimize-builld/ffmpeg-jni-rules.cjs +28 -28
- package/files/buildCodeplay/fix-optimize-builld/fix-optimize-build.gradle +9 -9
- package/files/buildCodeplay/fix-optimize-builld/restore-android-r8-rules.cjs +30 -30
- package/files/buildCodeplay/huawei-privacy-entry.js +135 -135
- package/files/buildCodeplay/huawei-privacy.css +22 -22
- package/files/buildCodeplay/ios-ad-consent.cjs +56 -56
- package/files/buildCodeplay/ios-emi-admob-modification.js +25 -25
- package/files/buildCodeplay/newly added.txt +89 -89
- package/files/buildCodeplay/non-google-billing.pro +3 -3
- package/files/buildCodeplay/release-sync.config.json +4 -4
- package/files/buildCodeplay/remove-force-kotlin-disable.js +43 -43
- package/files/buildCodeplay/ruads.cjs +220 -220
- package/files/buildCodeplay/saf-mediastore-dependency.cjs +21 -21
- package/files/buildCodeplay/setSplashAnimation.js +2 -2
- package/files/buildCodeplay/setup-ruads.cjs +62 -62
- package/files/buildCodeplay/splash-setup.cjs +88 -88
- package/files/buildCodeplay/store-billing.cjs +43 -43
- package/files/buildCodeplay/tests/huawei-live-reload.test.cjs +60 -60
- package/files/buildCodeplay/tests/huawei-privacy.test.cjs +49 -49
- package/files/scripts-common/collect-startup-profile.js +134 -134
- package/files/scripts-common/generate-baseline-profile.js +218 -218
- package/files/take-screen-image.js +4453 -4414
- package/package.json +1 -1
- package/runtime/splash-ready.mjs +52 -52
- package/runtime/vk-ads/vk-ad-configuration.json +39 -39
- package/scripts/baseline-profile.test.cjs +189 -189
- package/scripts/ensure-current-build.test.cjs +128 -28
- package/scripts/ios-ad-consent.test.cjs +99 -99
- package/scripts/ruads-install.test.cjs +197 -197
- package/scripts/ruads-policy.test.cjs +174 -174
- package/scripts/saf-mediastore-dependency.test.cjs +44 -44
- package/scripts/splash-setup.test.cjs +142 -142
- package/scripts/sync-files.js +1 -1
- package/scripts/vite-build-settings.test.cjs +93 -93
|
@@ -1,66 +1,150 @@
|
|
|
1
1
|
const { test } = require('node:test');
|
|
2
2
|
const assert = require('node:assert/strict');
|
|
3
3
|
const fs = require('fs');
|
|
4
|
-
const os = require('os');
|
|
5
4
|
const path = require('path');
|
|
5
|
+
const vm = require('node:vm');
|
|
6
6
|
const { ensureCurrentBuild } = require('../files/buildCodeplay/ensure-current-build.cjs');
|
|
7
7
|
const { removeVersionedBuildScripts } = require('../files/buildCodeplay/project-scripts.cjs');
|
|
8
8
|
|
|
9
|
-
function
|
|
10
|
-
const
|
|
11
|
-
|
|
9
|
+
function installPackage(root) {
|
|
10
|
+
const directory = path.join(root, 'node_modules', 'codeplay-common');
|
|
11
|
+
fs.mkdirSync(path.join(directory, 'scripts'), { recursive: true });
|
|
12
|
+
fs.writeFileSync(path.join(directory, 'package.json'), JSON.stringify({ name: 'codeplay-common', version: '4.11.38' }));
|
|
13
|
+
fs.writeFileSync(path.join(directory, 'scripts', 'sync-files.js'), '');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function fixture(t, names = [], options = {}) {
|
|
17
|
+
const temporaryRoot = path.resolve(__dirname, '../agent-temp/ensure-current-build-tests');
|
|
18
|
+
fs.mkdirSync(temporaryRoot, { recursive: true });
|
|
19
|
+
const root = fs.mkdtempSync(path.join(temporaryRoot, 'app-'));
|
|
20
|
+
t.after(() => {
|
|
21
|
+
assert.equal(path.dirname(path.resolve(root)), temporaryRoot);
|
|
22
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
23
|
+
});
|
|
12
24
|
fs.mkdirSync(path.join(root, 'buildCodeplay'));
|
|
13
25
|
for (const name of ['codeplayBeforeBuild.js', ...names]) fs.writeFileSync(path.join(root, 'buildCodeplay', name), '');
|
|
26
|
+
fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify({ name: 'test-app', ...options.manifest }));
|
|
27
|
+
if (options.installed !== false) installPackage(root);
|
|
14
28
|
return root;
|
|
15
29
|
}
|
|
16
30
|
|
|
17
|
-
test('current structure continues without npm commands', t => {
|
|
31
|
+
test('healthy current structure continues without npm or installer commands', t => {
|
|
18
32
|
const projectRoot = fixture(t, ['versions.json', 'custom-helper.js']);
|
|
19
|
-
assert.equal(ensureCurrentBuild({
|
|
33
|
+
assert.equal(ensureCurrentBuild({
|
|
34
|
+
projectRoot,
|
|
35
|
+
runNpm: () => assert.fail('unexpected npm command'),
|
|
36
|
+
runInstaller: () => assert.fail('unexpected installer command'),
|
|
37
|
+
runBeforeBuild: () => assert.fail('unexpected restart'),
|
|
38
|
+
}), false);
|
|
20
39
|
});
|
|
21
40
|
|
|
22
|
-
test('legacy files
|
|
41
|
+
test('legacy files migrate even when npm skips lifecycle scripts for an unchanged package', t => {
|
|
23
42
|
const projectRoot = fixture(t, ['codeplayBeforeBuild-6.7.js', 'setSplashAnimation-1.2.mjs']);
|
|
24
43
|
const calls = [];
|
|
25
44
|
assert.equal(ensureCurrentBuild({
|
|
26
45
|
projectRoot,
|
|
27
|
-
runNpm(command)
|
|
28
|
-
|
|
29
|
-
|
|
46
|
+
runNpm: command => calls.push(command),
|
|
47
|
+
runInstaller(script) {
|
|
48
|
+
assert.equal(script, path.join(projectRoot, 'node_modules/codeplay-common/scripts/sync-files.js'));
|
|
49
|
+
calls.push('installer');
|
|
50
|
+
removeVersionedBuildScripts(projectRoot);
|
|
30
51
|
},
|
|
31
52
|
runBeforeBuild(script) {
|
|
32
53
|
assert.equal(script, path.join(projectRoot, 'buildCodeplay', 'codeplayBeforeBuild.js'));
|
|
33
54
|
calls.push('fresh preparation');
|
|
34
55
|
},
|
|
35
56
|
}), true);
|
|
36
|
-
assert.deepEqual(calls, ['npm
|
|
57
|
+
assert.deepEqual(calls, ['npm install codeplay-common', 'installer', 'fresh preparation']);
|
|
37
58
|
});
|
|
38
59
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
60
|
+
test('interrupted uninstall with no dependency declaration is recovered before preparation', t => {
|
|
61
|
+
const projectRoot = fixture(t, [], { installed: false });
|
|
62
|
+
const calls = [];
|
|
63
|
+
assert.equal(ensureCurrentBuild({
|
|
64
|
+
projectRoot,
|
|
65
|
+
runNpm(command) { calls.push(command); installPackage(projectRoot); },
|
|
66
|
+
runBeforeBuild() {
|
|
67
|
+
assert.equal(JSON.parse(fs.readFileSync(path.join(projectRoot, 'node_modules/codeplay-common/package.json'))).version, '4.11.38');
|
|
68
|
+
calls.push('fresh preparation');
|
|
69
|
+
},
|
|
70
|
+
}), true);
|
|
71
|
+
assert.deepEqual(calls, ['npm install codeplay-common', 'fresh preparation']);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
for (const manifest of [
|
|
75
|
+
{ dependencies: { 'codeplay-common': '^4.11.38' } },
|
|
76
|
+
{ devDependencies: { 'codeplay-common': 'file:../common-source' } },
|
|
77
|
+
{ optionalDependencies: { 'codeplay-common': '4.11.38' } },
|
|
78
|
+
]) {
|
|
79
|
+
test(`recovery preserves declared ${Object.keys(manifest)[0]} specification`, t => {
|
|
80
|
+
const projectRoot = fixture(t, [], { installed: false, manifest });
|
|
81
|
+
const packagePath = path.join(projectRoot, 'package.json');
|
|
82
|
+
const original = fs.readFileSync(packagePath, 'utf8');
|
|
83
|
+
assert.equal(ensureCurrentBuild({
|
|
44
84
|
projectRoot,
|
|
45
|
-
runNpm(command) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
runBeforeBuild: () => assert.fail('must not continue'),
|
|
50
|
-
}), /npm failed/);
|
|
51
|
-
assert.equal(calls.at(-1), failedCommand);
|
|
85
|
+
runNpm(command) { assert.equal(command, 'npm install'); installPackage(projectRoot); },
|
|
86
|
+
runBeforeBuild() {},
|
|
87
|
+
}), true);
|
|
88
|
+
assert.equal(fs.readFileSync(packagePath, 'utf8'), original);
|
|
52
89
|
});
|
|
53
90
|
}
|
|
54
91
|
|
|
55
|
-
|
|
92
|
+
for (const incompleteFile of ['package.json', 'scripts/sync-files.js']) {
|
|
93
|
+
test(`incomplete package with damaged ${incompleteFile} is repaired`, t => {
|
|
94
|
+
const projectRoot = fixture(t);
|
|
95
|
+
const file = path.join(projectRoot, 'node_modules/codeplay-common', incompleteFile);
|
|
96
|
+
if (incompleteFile === 'package.json') fs.writeFileSync(file, '{');
|
|
97
|
+
else fs.unlinkSync(file);
|
|
98
|
+
let installs = 0;
|
|
99
|
+
assert.equal(ensureCurrentBuild({
|
|
100
|
+
projectRoot,
|
|
101
|
+
runNpm() { installs++; installPackage(projectRoot); },
|
|
102
|
+
runBeforeBuild() {},
|
|
103
|
+
}), true);
|
|
104
|
+
assert.equal(installs, 1);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
test('npm failure stops before running refreshed preparation', t => {
|
|
109
|
+
const projectRoot = fixture(t, [], { installed: false });
|
|
110
|
+
assert.throws(() => ensureCurrentBuild({
|
|
111
|
+
projectRoot,
|
|
112
|
+
runNpm() { throw Object.assign(new Error('npm failed'), { status: 9 }); },
|
|
113
|
+
runBeforeBuild: () => assert.fail('must not continue'),
|
|
114
|
+
}), { message: 'npm failed', status: 9 });
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('incomplete recovery stops without restarting or retrying indefinitely', t => {
|
|
118
|
+
const projectRoot = fixture(t, [], { installed: false });
|
|
119
|
+
let installs = 0;
|
|
120
|
+
assert.throws(() => ensureCurrentBuild({
|
|
121
|
+
projectRoot,
|
|
122
|
+
runNpm() { installs++; },
|
|
123
|
+
runBeforeBuild: () => assert.fail('must not continue'),
|
|
124
|
+
}), /still missing or incomplete after npm install/);
|
|
125
|
+
assert.equal(installs, 1);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('installer failure stops preparation', t => {
|
|
129
|
+
const projectRoot = fixture(t, ['add-splash-screen-1.0.js']);
|
|
130
|
+
assert.throws(() => ensureCurrentBuild({
|
|
131
|
+
projectRoot,
|
|
132
|
+
runNpm() {},
|
|
133
|
+
runInstaller() { throw new Error('migration failed'); },
|
|
134
|
+
runBeforeBuild: () => assert.fail('must not continue'),
|
|
135
|
+
}), /migration failed/);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test('unknown versioned files stop without deleting app files or looping', t => {
|
|
56
139
|
const projectRoot = fixture(t, ['custom-helper-1.0.js']);
|
|
57
140
|
const calls = [];
|
|
58
141
|
assert.throws(() => ensureCurrentBuild({
|
|
59
142
|
projectRoot,
|
|
60
143
|
runNpm: command => calls.push(command),
|
|
144
|
+
runInstaller() { calls.push('installer'); removeVersionedBuildScripts(projectRoot); },
|
|
61
145
|
runBeforeBuild: () => assert.fail('must not continue'),
|
|
62
146
|
}), /Legacy buildCodeplay files remain/);
|
|
63
|
-
assert.deepEqual(calls, ['npm
|
|
147
|
+
assert.deepEqual(calls, ['npm install codeplay-common', 'installer']);
|
|
64
148
|
assert.ok(fs.existsSync(path.join(projectRoot, 'buildCodeplay', 'custom-helper-1.0.js')));
|
|
65
149
|
});
|
|
66
150
|
|
|
@@ -68,9 +152,25 @@ test('failed refreshed preparation propagates to stop the build', t => {
|
|
|
68
152
|
const projectRoot = fixture(t, ['packageidBaseModification-1.0.js']);
|
|
69
153
|
assert.throws(() => ensureCurrentBuild({
|
|
70
154
|
projectRoot,
|
|
71
|
-
runNpm(
|
|
72
|
-
|
|
73
|
-
},
|
|
155
|
+
runNpm() { removeVersionedBuildScripts(projectRoot); },
|
|
156
|
+
runInstaller: () => assert.fail('npm already migrated the templates'),
|
|
74
157
|
runBeforeBuild() { throw Object.assign(new Error('preparation failed'), { status: 7 }); },
|
|
75
158
|
}), { message: 'preparation failed', status: 7 });
|
|
76
159
|
});
|
|
160
|
+
|
|
161
|
+
test('normal version update installs directly without removing the working dependency', () => {
|
|
162
|
+
const source = fs.readFileSync(path.join(__dirname, '../files/buildCodeplay/codeplayBeforeBuild.js'), 'utf8');
|
|
163
|
+
const functionSource = source.slice(source.indexOf('function checkPackageVersion()'), source.indexOf('// Run package version check'));
|
|
164
|
+
const calls = [];
|
|
165
|
+
vm.runInNewContext(`${functionSource}\ncheckPackageVersion();`, {
|
|
166
|
+
fs: { readFileSync: () => JSON.stringify({ dependencies: { 'codeplay-common': '^4.11.37' } }) },
|
|
167
|
+
packageJsonPath: 'package.json',
|
|
168
|
+
getInstalledVersion: () => '4.11.37',
|
|
169
|
+
getLatestVersion: () => '4.11.38',
|
|
170
|
+
compareVersionStrings: () => -1,
|
|
171
|
+
execSync: command => calls.push(command),
|
|
172
|
+
console: { log() {}, error() {} },
|
|
173
|
+
process: { exit: () => assert.fail('must not exit') },
|
|
174
|
+
});
|
|
175
|
+
assert.deepEqual(calls, ['npm install codeplay-common']);
|
|
176
|
+
});
|
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
const { test } = require('node:test');
|
|
2
|
-
const assert = require('node:assert/strict');
|
|
3
|
-
const fs = require('node:fs');
|
|
4
|
-
const path = require('node:path');
|
|
5
|
-
const { prepareIOSAdConsent } = require('../files/buildCodeplay/ios-ad-consent.cjs');
|
|
6
|
-
const { createRequire } = require('node:module');
|
|
7
|
-
const vm = require('node:vm');
|
|
8
|
-
const { install } = require('./sync-files.js');
|
|
9
|
-
|
|
10
|
-
function fixture(t, sources) {
|
|
11
|
-
const tempRoot = path.resolve(__dirname, '../agent-temp/ios-ad-consent-tests');
|
|
12
|
-
fs.mkdirSync(tempRoot, { recursive: true });
|
|
13
|
-
const root = fs.mkdtempSync(path.join(tempRoot, 'case-'));
|
|
14
|
-
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
15
|
-
for (const [name, content] of Object.entries(sources)) {
|
|
16
|
-
const file = path.join(root, 'ios/App/App', name);
|
|
17
|
-
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
18
|
-
fs.writeFileSync(file, content);
|
|
19
|
-
}
|
|
20
|
-
return { root, read: name => fs.readFileSync(path.join(root, 'ios/App/App', name), 'utf8') };
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const legacyScene = `import UIKit
|
|
24
|
-
import AppTrackingTransparency
|
|
25
|
-
class SceneDelegate {
|
|
26
|
-
private var isTrackingAuthorizationRequestScheduled = false
|
|
27
|
-
func sceneDidBecomeActive() {
|
|
28
|
-
if ATTrackingManager.trackingAuthorizationStatus == .notDetermined &&
|
|
29
|
-
!isTrackingAuthorizationRequestScheduled {
|
|
30
|
-
isTrackingAuthorizationRequestScheduled = true
|
|
31
|
-
|
|
32
|
-
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
|
|
33
|
-
self?.isTrackingAuthorizationRequestScheduled = false
|
|
34
|
-
|
|
35
|
-
guard UIApplication.shared.applicationState == .active,
|
|
36
|
-
ATTrackingManager.trackingAuthorizationStatus == .notDetermined else { return }
|
|
37
|
-
|
|
38
|
-
ATTrackingManager.requestTrackingAuthorization { _ in }
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
keepOtherStartupCode()
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
`;
|
|
45
|
-
|
|
46
|
-
test('removes the known scene startup request with LF, CRLF and changed indentation', t => {
|
|
47
|
-
for (const source of [legacyScene, legacyScene.replace(/\n/g, '\r\n'), legacyScene.replace(/ /g, '\t')]) {
|
|
48
|
-
const f = fixture(t, { 'SceneDelegate.swift': source });
|
|
49
|
-
assert.equal(prepareIOSAdConsent(f.root, () => {}).length, 1);
|
|
50
|
-
assert.doesNotMatch(f.read('SceneDelegate.swift'), /ATTrackingManager|AppTrackingTransparency|isTrackingAuthorizationRequestScheduled/);
|
|
51
|
-
assert.match(f.read('SceneDelegate.swift'), /keepOtherStartupCode\(\)/);
|
|
52
|
-
assert.deepEqual(prepareIOSAdConsent(f.root, () => {}), [], 'Migration is idempotent');
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('rejects an AppDelegate ATT request even without a SceneDelegate', t => {
|
|
57
|
-
const source = 'ATTrackingManager\n .requestTrackingAuthorization { _ in }';
|
|
58
|
-
const f = fixture(t, { 'AppDelegate.swift': source });
|
|
59
|
-
assert.throws(() => prepareIOSAdConsent(f.root, () => {}), /AppDelegate.swift requests ATT/);
|
|
60
|
-
assert.equal(f.read('AppDelegate.swift'), source);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('checks nested app code and validates everything before migrating the scene', t => {
|
|
64
|
-
const f = fixture(t, {
|
|
65
|
-
'SceneDelegate.swift': legacyScene,
|
|
66
|
-
'Startup/Permissions.m': '[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:handler];',
|
|
67
|
-
});
|
|
68
|
-
assert.throws(() => prepareIOSAdConsent(f.root, () => {}), /Permissions.m requests ATT/);
|
|
69
|
-
assert.equal(f.read('SceneDelegate.swift'), legacyScene, 'No partial edits when validation fails');
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('preserves custom native code and ignores commented ATT examples', t => {
|
|
73
|
-
const source = '// ATTrackingManager.requestTrackingAuthorization { _ in }\n/* ATTrackingManager.requestTrackingAuthorization */\nkeepOtherStartupCode()';
|
|
74
|
-
const f = fixture(t, { 'AppDelegate.swift': source });
|
|
75
|
-
assert.deepEqual(prepareIOSAdConsent(f.root, () => {}), []);
|
|
76
|
-
assert.equal(f.read('AppDelegate.swift'), source);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test('installer ships the guard and generated before-build invokes it from the consuming app', t => {
|
|
80
|
-
const f = fixture(t, { 'SceneDelegate.swift': legacyScene });
|
|
81
|
-
fs.writeFileSync(path.join(f.root, 'package.json'), JSON.stringify({ name: 'consent-fixture', scripts: {} }));
|
|
82
|
-
fs.writeFileSync(path.join(f.root, 'capacitor.config.json'), JSON.stringify({ appId: 'fixture.app' }));
|
|
83
|
-
install({ projectRoot: f.root, copyAssets: false });
|
|
84
|
-
const beforeBuild = path.join(f.root, 'buildCodeplay/codeplayBeforeBuild.js');
|
|
85
|
-
const source = fs.readFileSync(beforeBuild, 'utf8').replace(/\r\n/g, '\n');
|
|
86
|
-
const start = source.indexOf('function updateIOSStartupForAdConsent() {');
|
|
87
|
-
const end = source.indexOf('\n\n\ntry {', start);
|
|
88
|
-
assert.ok(start >= 0 && end > start);
|
|
89
|
-
assert.ok(fs.existsSync(path.join(f.root, 'buildCodeplay/ios-ad-consent.cjs')));
|
|
90
|
-
vm.runInNewContext(source.slice(start, end) + '\nupdateIOSStartupForAdConsent();', {
|
|
91
|
-
require: createRequire(beforeBuild), process: { cwd: () => f.root },
|
|
92
|
-
});
|
|
93
|
-
assert.doesNotMatch(f.read('SceneDelegate.swift'), /requestTrackingAuthorization/);
|
|
94
|
-
assert.match(f.read('SceneDelegate.swift'), /keepOtherStartupCode\(\)/);
|
|
95
|
-
fs.writeFileSync(path.join(f.root, 'ios/App/App/AppDelegate.swift'), 'ATTrackingManager.requestTrackingAuthorization { _ in }');
|
|
96
|
-
assert.throws(() => vm.runInNewContext(source.slice(start, end) + '\nupdateIOSStartupForAdConsent();', {
|
|
97
|
-
require: createRequire(beforeBuild), process: { cwd: () => f.root },
|
|
98
|
-
}), /AppDelegate.swift requests ATT/);
|
|
99
|
-
});
|
|
1
|
+
const { test } = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const { prepareIOSAdConsent } = require('../files/buildCodeplay/ios-ad-consent.cjs');
|
|
6
|
+
const { createRequire } = require('node:module');
|
|
7
|
+
const vm = require('node:vm');
|
|
8
|
+
const { install } = require('./sync-files.js');
|
|
9
|
+
|
|
10
|
+
function fixture(t, sources) {
|
|
11
|
+
const tempRoot = path.resolve(__dirname, '../agent-temp/ios-ad-consent-tests');
|
|
12
|
+
fs.mkdirSync(tempRoot, { recursive: true });
|
|
13
|
+
const root = fs.mkdtempSync(path.join(tempRoot, 'case-'));
|
|
14
|
+
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
15
|
+
for (const [name, content] of Object.entries(sources)) {
|
|
16
|
+
const file = path.join(root, 'ios/App/App', name);
|
|
17
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
18
|
+
fs.writeFileSync(file, content);
|
|
19
|
+
}
|
|
20
|
+
return { root, read: name => fs.readFileSync(path.join(root, 'ios/App/App', name), 'utf8') };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const legacyScene = `import UIKit
|
|
24
|
+
import AppTrackingTransparency
|
|
25
|
+
class SceneDelegate {
|
|
26
|
+
private var isTrackingAuthorizationRequestScheduled = false
|
|
27
|
+
func sceneDidBecomeActive() {
|
|
28
|
+
if ATTrackingManager.trackingAuthorizationStatus == .notDetermined &&
|
|
29
|
+
!isTrackingAuthorizationRequestScheduled {
|
|
30
|
+
isTrackingAuthorizationRequestScheduled = true
|
|
31
|
+
|
|
32
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
|
|
33
|
+
self?.isTrackingAuthorizationRequestScheduled = false
|
|
34
|
+
|
|
35
|
+
guard UIApplication.shared.applicationState == .active,
|
|
36
|
+
ATTrackingManager.trackingAuthorizationStatus == .notDetermined else { return }
|
|
37
|
+
|
|
38
|
+
ATTrackingManager.requestTrackingAuthorization { _ in }
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
keepOtherStartupCode()
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
`;
|
|
45
|
+
|
|
46
|
+
test('removes the known scene startup request with LF, CRLF and changed indentation', t => {
|
|
47
|
+
for (const source of [legacyScene, legacyScene.replace(/\n/g, '\r\n'), legacyScene.replace(/ /g, '\t')]) {
|
|
48
|
+
const f = fixture(t, { 'SceneDelegate.swift': source });
|
|
49
|
+
assert.equal(prepareIOSAdConsent(f.root, () => {}).length, 1);
|
|
50
|
+
assert.doesNotMatch(f.read('SceneDelegate.swift'), /ATTrackingManager|AppTrackingTransparency|isTrackingAuthorizationRequestScheduled/);
|
|
51
|
+
assert.match(f.read('SceneDelegate.swift'), /keepOtherStartupCode\(\)/);
|
|
52
|
+
assert.deepEqual(prepareIOSAdConsent(f.root, () => {}), [], 'Migration is idempotent');
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('rejects an AppDelegate ATT request even without a SceneDelegate', t => {
|
|
57
|
+
const source = 'ATTrackingManager\n .requestTrackingAuthorization { _ in }';
|
|
58
|
+
const f = fixture(t, { 'AppDelegate.swift': source });
|
|
59
|
+
assert.throws(() => prepareIOSAdConsent(f.root, () => {}), /AppDelegate.swift requests ATT/);
|
|
60
|
+
assert.equal(f.read('AppDelegate.swift'), source);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('checks nested app code and validates everything before migrating the scene', t => {
|
|
64
|
+
const f = fixture(t, {
|
|
65
|
+
'SceneDelegate.swift': legacyScene,
|
|
66
|
+
'Startup/Permissions.m': '[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:handler];',
|
|
67
|
+
});
|
|
68
|
+
assert.throws(() => prepareIOSAdConsent(f.root, () => {}), /Permissions.m requests ATT/);
|
|
69
|
+
assert.equal(f.read('SceneDelegate.swift'), legacyScene, 'No partial edits when validation fails');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('preserves custom native code and ignores commented ATT examples', t => {
|
|
73
|
+
const source = '// ATTrackingManager.requestTrackingAuthorization { _ in }\n/* ATTrackingManager.requestTrackingAuthorization */\nkeepOtherStartupCode()';
|
|
74
|
+
const f = fixture(t, { 'AppDelegate.swift': source });
|
|
75
|
+
assert.deepEqual(prepareIOSAdConsent(f.root, () => {}), []);
|
|
76
|
+
assert.equal(f.read('AppDelegate.swift'), source);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('installer ships the guard and generated before-build invokes it from the consuming app', t => {
|
|
80
|
+
const f = fixture(t, { 'SceneDelegate.swift': legacyScene });
|
|
81
|
+
fs.writeFileSync(path.join(f.root, 'package.json'), JSON.stringify({ name: 'consent-fixture', scripts: {} }));
|
|
82
|
+
fs.writeFileSync(path.join(f.root, 'capacitor.config.json'), JSON.stringify({ appId: 'fixture.app' }));
|
|
83
|
+
install({ projectRoot: f.root, copyAssets: false });
|
|
84
|
+
const beforeBuild = path.join(f.root, 'buildCodeplay/codeplayBeforeBuild.js');
|
|
85
|
+
const source = fs.readFileSync(beforeBuild, 'utf8').replace(/\r\n/g, '\n');
|
|
86
|
+
const start = source.indexOf('function updateIOSStartupForAdConsent() {');
|
|
87
|
+
const end = source.indexOf('\n\n\ntry {', start);
|
|
88
|
+
assert.ok(start >= 0 && end > start);
|
|
89
|
+
assert.ok(fs.existsSync(path.join(f.root, 'buildCodeplay/ios-ad-consent.cjs')));
|
|
90
|
+
vm.runInNewContext(source.slice(start, end) + '\nupdateIOSStartupForAdConsent();', {
|
|
91
|
+
require: createRequire(beforeBuild), process: { cwd: () => f.root },
|
|
92
|
+
});
|
|
93
|
+
assert.doesNotMatch(f.read('SceneDelegate.swift'), /requestTrackingAuthorization/);
|
|
94
|
+
assert.match(f.read('SceneDelegate.swift'), /keepOtherStartupCode\(\)/);
|
|
95
|
+
fs.writeFileSync(path.join(f.root, 'ios/App/App/AppDelegate.swift'), 'ATTrackingManager.requestTrackingAuthorization { _ in }');
|
|
96
|
+
assert.throws(() => vm.runInNewContext(source.slice(start, end) + '\nupdateIOSStartupForAdConsent();', {
|
|
97
|
+
require: createRequire(beforeBuild), process: { cwd: () => f.root },
|
|
98
|
+
}), /AppDelegate.swift requests ATT/);
|
|
99
|
+
});
|