summaryrefslogtreecommitdiff
path: root/packages/astro/test/experimental-content-collections-cache-invalidation.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/astro/test/experimental-content-collections-cache-invalidation.test.js')
-rw-r--r--packages/astro/test/experimental-content-collections-cache-invalidation.test.js98
1 files changed, 98 insertions, 0 deletions
diff --git a/packages/astro/test/experimental-content-collections-cache-invalidation.test.js b/packages/astro/test/experimental-content-collections-cache-invalidation.test.js
new file mode 100644
index 000000000..5ec688a91
--- /dev/null
+++ b/packages/astro/test/experimental-content-collections-cache-invalidation.test.js
@@ -0,0 +1,98 @@
+import assert from 'node:assert/strict';
+import { after, before, describe, it } from 'node:test';
+import { loadFixture } from './test-utils.js';
+import fs from 'node:fs';
+import { copyFiles } from '../dist/core/build/static-build.js';
+
+describe('Experimental Content Collections cache - invalidation', () => {
+ class CacheBackup {
+ constructor(root, relCacheDir) {
+ this.root = new URL(root, import.meta.url);
+ this.cacheDir = new URL(relCacheDir, this.root);
+ this.tmpDir = new URL(`./tmp` + relCacheDir.slice(1), this.root);
+ }
+ backup() {
+ this.rmTmp();
+ copyFiles(this.cacheDir, this.tmpDir);
+ }
+ restore() {
+ fs.rmSync(this.cacheDir, { recursive: true });
+ copyFiles(this.tmpDir, this.cacheDir);
+ }
+ rmTmp() {
+ fs.rmSync(this.tmpDir, { force: true, recursive: true });
+ }
+ }
+
+ class ManifestTestPlugin {
+ used = false;
+ plugin() {
+ return {
+ name: '@test/manifest-used',
+ hooks: {
+ 'astro:build:done': ({ cacheManifest }) => {
+ this.used = cacheManifest;
+ }
+ }
+ }
+ }
+ }
+
+ describe('manifest version', () => {
+ let fixture, backup,
+ /** @type {ManifestTestPlugin} */
+ testPlugin;
+ before(async () => {
+ testPlugin = new ManifestTestPlugin();
+ fixture = await loadFixture({
+ root: './fixtures/content-collections-cache-invalidation/',
+ cacheDir: './cache/version-mismatch/',
+ experimental: { contentCollectionCache: true },
+ integrations: [
+ testPlugin.plugin()
+ ]
+ });
+ backup = new CacheBackup('./fixtures/content-collections-cache-invalidation/', './cache/version-mismatch/');
+ backup.backup();
+ await fixture.build();
+ });
+
+ after(async () => {
+ backup.restore();
+ //await fixture.clean();
+ });
+
+ it('Manifest was not used', () => {
+ assert.equal(testPlugin.used, false, 'manifest not used because of version mismatch');
+ });
+ });
+
+ describe('lockfiles', () => {
+ let fixture, backup,
+ /** @type {ManifestTestPlugin} */
+ testPlugin;
+ before(async () => {
+ testPlugin = new ManifestTestPlugin();
+ fixture = await loadFixture({
+ root: './fixtures/content-collections-cache-invalidation/',
+ cacheDir: './cache/lockfile-mismatch/',
+ experimental: { contentCollectionCache: true },
+ integrations: [
+ testPlugin.plugin()
+ ]
+ });
+ backup = new CacheBackup('./fixtures/content-collections-cache-invalidation/', './cache/lockfile-mismatch/');
+ backup.backup();
+ await fixture.build();
+ });
+
+ after(async () => {
+ backup.restore();
+ //await fixture.clean();
+ });
+
+ it('Manifest was not used', () => {
+ assert.equal(testPlugin.used, false, 'manifest not used because of lockfile mismatch');
+ });
+ });
+});