Skip to content

Commit ad3810e

Browse files
committed
chore: add tests
1 parent fe35a5d commit ad3810e

File tree

3 files changed

+100
-1
lines changed

3 files changed

+100
-1
lines changed

src/helpers/files.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ exports.moveStaticPages = async ({ netlifyConfig, target, i18n, failBuild }) =>
1919
const moveFile = async (file) => {
2020
const source = join(root, file)
2121
files.push(file)
22-
const dest = join(netlifyConfig.build.publish, source)
22+
const dest = join(netlifyConfig.build.publish, file)
2323
await move(source, dest)
2424
}
2525
// Move all static files, except error documents and nft manifests

test/__snapshots__/index.js.snap

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,62 @@ exports.resolvePages = () => {
6868
}"
6969
`;
7070

71+
exports[`onBuild() generates static files manifest 1`] = `
72+
Array [
73+
"en/getStaticProps/1.html",
74+
"en/getStaticProps/1.json",
75+
"en/getStaticProps/2.html",
76+
"en/getStaticProps/2.json",
77+
"en/getStaticProps/static.html",
78+
"en/getStaticProps/static.json",
79+
"en/getStaticProps/with-revalidate.html",
80+
"en/getStaticProps/with-revalidate.json",
81+
"en/getStaticProps/withFallback/3.html",
82+
"en/getStaticProps/withFallback/3.json",
83+
"en/getStaticProps/withFallback/4.html",
84+
"en/getStaticProps/withFallback/4.json",
85+
"en/getStaticProps/withFallback/my/path/1.html",
86+
"en/getStaticProps/withFallback/my/path/1.json",
87+
"en/getStaticProps/withFallback/my/path/2.html",
88+
"en/getStaticProps/withFallback/my/path/2.json",
89+
"en/getStaticProps/withFallbackBlocking/3.html",
90+
"en/getStaticProps/withFallbackBlocking/3.json",
91+
"en/getStaticProps/withFallbackBlocking/4.html",
92+
"en/getStaticProps/withFallbackBlocking/4.json",
93+
"en/getStaticProps/withRevalidate/1.html",
94+
"en/getStaticProps/withRevalidate/1.json",
95+
"en/getStaticProps/withRevalidate/2.html",
96+
"en/getStaticProps/withRevalidate/2.json",
97+
"en/getStaticProps/withRevalidate/withFallback/1.html",
98+
"en/getStaticProps/withRevalidate/withFallback/1.json",
99+
"en/getStaticProps/withRevalidate/withFallback/2.html",
100+
"en/getStaticProps/withRevalidate/withFallback/2.json",
101+
"en/image.html",
102+
"en/middle.html",
103+
"en/previewTest.html",
104+
"en/previewTest.json",
105+
"en/static.html",
106+
"es/getStaticProps/static.html",
107+
"es/getStaticProps/static.json",
108+
"es/getStaticProps/with-revalidate.html",
109+
"es/getStaticProps/with-revalidate.json",
110+
"es/image.html",
111+
"es/middle.html",
112+
"es/previewTest.html",
113+
"es/previewTest.json",
114+
"es/static.html",
115+
"fr/getStaticProps/static.html",
116+
"fr/getStaticProps/static.json",
117+
"fr/getStaticProps/with-revalidate.html",
118+
"fr/getStaticProps/with-revalidate.json",
119+
"fr/image.html",
120+
"fr/middle.html",
121+
"fr/previewTest.html",
122+
"fr/previewTest.json",
123+
"fr/static.html",
124+
]
125+
`;
126+
71127
exports[`onBuild() writes correct redirects to netlifyConfig 1`] = `
72128
Array [
73129
Object {

test/index.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,49 @@ describe('onBuild()', () => {
203203
expect(existsSync(path.resolve('.next/BUILD_ID'))).toBeTruthy()
204204
})
205205

206+
test('generates static files manifest', async () => {
207+
await moveNextDist()
208+
process.env.EXPERIMENTAL_MOVE_STATIC_PAGES = 'true'
209+
await plugin.onBuild(defaultArgs)
210+
expect(existsSync(path.resolve('.next/static-manifest.json'))).toBeTruthy()
211+
const data = JSON.parse(readFileSync(path.resolve('.next/static-manifest.json'), 'utf8'))
212+
expect(data).toMatchSnapshot()
213+
delete process.env.EXPERIMENTAL_MOVE_STATIC_PAGES
214+
})
215+
216+
test('moves static files to root', async () => {
217+
await moveNextDist()
218+
process.env.EXPERIMENTAL_MOVE_STATIC_PAGES = 'true'
219+
await plugin.onBuild(defaultArgs)
220+
const data = JSON.parse(readFileSync(path.resolve('.next/static-manifest.json'), 'utf8'))
221+
222+
data.forEach((file) => {
223+
expect(existsSync(path.resolve(path.join('.next', file)))).toBeTruthy()
224+
expect(existsSync(path.resolve(path.join('.next', 'server', 'pages', file)))).toBeFalsy()
225+
})
226+
227+
delete process.env.EXPERIMENTAL_MOVE_STATIC_PAGES
228+
})
229+
230+
test('copies default locale files to top level', async () => {
231+
await moveNextDist()
232+
process.env.EXPERIMENTAL_MOVE_STATIC_PAGES = 'true'
233+
await plugin.onBuild(defaultArgs)
234+
const data = JSON.parse(readFileSync(path.resolve('.next/static-manifest.json'), 'utf8'))
235+
236+
const locale = 'en/'
237+
238+
data.forEach((file) => {
239+
if (!file.startsWith(locale)) {
240+
return
241+
}
242+
const trimmed = file.substring(locale.length)
243+
expect(existsSync(path.resolve(path.join('.next', trimmed)))).toBeTruthy()
244+
})
245+
246+
delete process.env.EXPERIMENTAL_MOVE_STATIC_PAGES
247+
})
248+
206249
test('sets correct config', async () => {
207250
await moveNextDist()
208251

0 commit comments

Comments
 (0)