1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
import assert from 'node:assert/strict';
import fs from 'node:fs';
import { after, before, describe, it } from 'node:test';
import { copyFiles } from '../dist/core/build/static-build.js';
import { loadFixture } from './test-utils.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');
});
});
describe('duplicate content', () => {
let fixture,
backup,
/** @type {ManifestTestPlugin} */
testPlugin;
before(async () => {
testPlugin = new ManifestTestPlugin();
fixture = await loadFixture({
root: './fixtures/content-collections-same-contents/',
cacheDir: './cache/same-contents/',
experimental: { contentCollectionCache: true },
integrations: [testPlugin.plugin()],
});
backup = new CacheBackup(
'./fixtures/content-collections-same-contents/',
'./cache/same-contents/',
);
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');
});
});
});
|