Files
ep-mail-client/tests/build-version.test.cjs

82 lines
4.6 KiB
JavaScript

const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const root = path.resolve(__dirname, '..');
const packageJson = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
const packageLock = JSON.parse(fs.readFileSync(path.join(root, 'package-lock.json'), 'utf8'));
const androidBuild = fs.readFileSync(path.join(root, 'android', 'app', 'build.gradle'), 'utf8');
const buildAll = fs.readFileSync(path.join(root, 'scripts', 'build-all.ps1'), 'utf8');
const build = fs.readFileSync(path.join(root, 'scripts', 'build.ps1'), 'utf8');
const linuxBuild = fs.readFileSync(path.join(root, 'scripts', 'build-linux-wsl.sh'), 'utf8');
const androidDebugScript = fs.readFileSync(path.join(root, 'scripts', 'build-android-apk.cjs'), 'utf8');
const androidReleaseScript = fs.readFileSync(path.join(root, 'scripts', 'build-android-release-apk.cjs'), 'utf8');
const desktopWorkflow = fs.readFileSync(path.join(root, '.github', 'workflows', 'desktop-build.yml'), 'utf8');
const androidRootBuild = fs.readFileSync(path.join(root, 'android', 'build.gradle'), 'utf8');
const androidProperties = fs.readFileSync(path.join(root, 'android', 'gradle.properties'), 'utf8');
const androidWrapper = fs.readFileSync(path.join(root, 'android', 'gradle', 'wrapper', 'gradle-wrapper.properties'), 'utf8');
test('package metadata and lockfile share one release version', () => {
assert.equal(packageLock.version, packageJson.version);
assert.equal(packageLock.packages[''].version, packageJson.version);
assert.match(packageJson.version, /^\d+\.\d+\.\d+$/);
});
test('Android version name and code derive from the canonical package version', () => {
assert.match(androidBuild, /parse\(file\("\.\.\/\.\.\/package\.json"\)\)\.version/);
assert.match(androidBuild, /versionName appVersion/);
assert.match(androidBuild, /versionCode appVersionParts\[0\] \* 10000 \+ appVersionParts\[1\] \* 100 \+ appVersionParts\[2\]/);
const parts = packageJson.version.split('.').map(Number);
const expectedCode = parts[0] * 10000 + parts[1] * 100 + parts[2];
assert.ok(Number.isSafeInteger(expectedCode) && expectedCode > 0);
assert.ok(parts[1] < 100 && parts[2] < 100, 'update the Android versionCode mapping before minor or patch reaches 100');
});
test('release scripts and desktop artifact labels use package.json version', () => {
assert.match(buildAll, /package\.json/);
assert.match(build, /package\.json/);
assert.match(desktopWorkflow, /require\('\.\/package\.json'\)\.version/);
assert.match(desktopWorkflow, /-v\$\{\{ steps\.app-version\.outputs\.version \}\}/);
});
test('build scripts retain the basic targets and add the Windows installer and isolated WSL builds', () => {
assert.match(build, /npm run android:apk/);
assert.match(build, /npm run dist:win:portable/);
assert.match(buildAll, /build\.ps1/);
assert.match(buildAll, /npm run dist:win:installer/);
assert.match(buildAll, /--distribution/);
assert.match(buildAll, /build-linux-wsl\.sh/);
assert.match(linuxBuild, /mktemp -d/);
assert.match(linuxBuild, /--exclude='\.\/node_modules'/);
assert.match(linuxBuild, /npm ci/);
assert.match(linuxBuild, /npm run dist:linux/);
assert.match(linuxBuild, /appimages=/);
assert.match(linuxBuild, /debs=/);
assert.doesNotMatch(linuxBuild, /\r/);
});
test('Android debug APK is labeled as debug and release APK requires signing credentials', () => {
assert.match(androidDebugScript, /assembleDebug/);
assert.match(androidDebugScript, /ep-mail \$\{version\}-debug\.apk/);
assert.match(androidReleaseScript, /assembleRelease/);
assert.match(androidReleaseScript, /EP_MAIL_ANDROID_STORE_FILE/);
assert.match(androidReleaseScript, /EP_MAIL_ANDROID_STORE_PASSWORD/);
assert.match(androidReleaseScript, /EP_MAIL_ANDROID_KEY_ALIAS/);
assert.match(androidReleaseScript, /EP_MAIL_ANDROID_KEY_PASSWORD/);
assert.match(androidReleaseScript, /ep-mail \$\{version\}\.apk/);
});
test('Android Gradle and generated Capacitor modules use a compatible plugin version', () => {
const plugin = androidRootBuild.match(/classpath 'com\.android\.tools\.build:gradle:([^']+)'/);
const forced = androidRootBuild.match(/resolutionStrategy\.force 'com\.android\.tools\.build:gradle:([^']+)'/);
assert.ok(plugin && forced);
assert.equal(plugin[1], forced[1]);
assert.equal(plugin[1], '9.4.0');
assert.match(androidWrapper, /gradle-9\.7\.1-bin\.zip/);
assert.match(androidProperties, /^android\.builtInKotlin=false$/m);
assert.match(androidProperties, /^android\.newDsl=false$/m);
assert.match(androidBuild, /getDefaultProguardFile\('proguard-android-optimize\.txt'\)/);
});