Skip to content
This repository was archived by the owner on May 10, 2021. It is now read-only.

Commit e010440

Browse files
committed
fix windows test
1 parent 1b4cb5a commit e010440

File tree

3 files changed

+57
-14
lines changed

3 files changed

+57
-14
lines changed

lib/helpers/getPagesManifest.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ const { readJSONSync } = require("fs-extra");
33
const { NEXT_DIST_DIR } = require("../config");
44

55
const getPagesManifest = () => {
6-
return readJSONSync(join(NEXT_DIST_DIR, "serverless", "pages-manifest.json"));
6+
const contents = readJSONSync(
7+
join(NEXT_DIST_DIR, "serverless", "pages-manifest.json")
8+
);
9+
// Next.js mistakenly puts backslashes in certain paths on Windows, replace
10+
Object.entries(contents).forEach(([key, value]) => {
11+
contents[key] = value.replace(/\\/g, "/");
12+
});
13+
return contents;
714
};
815

916
module.exports = getPagesManifest;

lib/pages/getStaticProps/redirects.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ pages.forEach(({ route, dataRoute, srcRoute }) => {
2626
const isNotDynamic = !srcRoute;
2727
if (isNotDynamic) {
2828
if (defaultLocale) {
29+
const defaultLocaleTarget = `/${defaultLocale}${route}`;
2930
redirects.push({
3031
route,
31-
target: `/${defaultLocale}${route}`,
32+
target: defaultLocaleTarget,
3233
});
3334
}
3435
locales.forEach((locale) => {
@@ -49,12 +50,12 @@ pages.forEach(({ route, dataRoute, srcRoute }) => {
4950
});
5051
} else {
5152
if (defaultLocale && !defaultLocaleRedirects.includes(srcRoute)) {
53+
const formattedSrcRoute = srcRoute.replace("[", ":").replace("]", "");
54+
const defaultLocaleTarget = `/${defaultLocale}${formattedSrcRoute}`;
5255
// Add redirect for /normal/:id -> /defaultLocale/normal/:id
5356
redirects.push({
5457
route: srcRoute,
55-
target: `/${defaultLocale}${srcRoute
56-
.replace("[", ":")
57-
.replace("]", "")}`,
58+
target: defaultLocaleTarget,
5859
});
5960
defaultLocaleRedirects.push(srcRoute);
6061
}

tests/i18n.test.js

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Test next-on-netlify when i18n is set in next.config.js (Next 10+)
22

3-
const { parse, join } = require("path");
3+
const { parse, join, sep } = require("path");
44
const {
55
existsSync,
66
readdirSync,
@@ -45,33 +45,68 @@ describe("next-on-netlify", () => {
4545
describe("next-on-netlify", () => {
4646
test("builds successfully", () => {
4747
expect(buildOutput).toMatch("Next on Netlify");
48-
expect(buildOutput).toMatch("Copying static NextJS assets to out_publish/");
4948
expect(buildOutput).toMatch(
50-
"Setting up API endpoints as Netlify Functions in out_functions/"
49+
`Copying static NextJS assets to out_publish${sep}`
5150
);
5251
expect(buildOutput).toMatch(
53-
"Setting up pages with getInitialProps as Netlify Functions in out_functions/"
52+
`Setting up API endpoints as Netlify Functions in out_functions${sep}`
5453
);
5554
expect(buildOutput).toMatch(
56-
"Setting up pages with getServerSideProps as Netlify Functions in out_functions/"
55+
`Setting up pages with getInitialProps as Netlify Functions in out_functions${sep}`
5756
);
5857
expect(buildOutput).toMatch(
59-
"Copying pre-rendered pages with getStaticProps and JSON data to out_publish/"
58+
`Setting up pages with getServerSideProps as Netlify Functions in out_functions${sep}`
6059
);
6160
expect(buildOutput).toMatch(
62-
"Setting up pages with getStaticProps and fallback: true as Netlify Functions in out_functions/"
61+
`Copying pre-rendered pages with getStaticProps and JSON data to out_publish${sep}`
6362
);
6463
expect(buildOutput).toMatch(
65-
"Setting up pages with getStaticProps and revalidation interval as Netlify Functions in out_functions/"
64+
`Setting up pages with getStaticProps and fallback: true as Netlify Functions in out_functions${sep}`
6665
);
6766
expect(buildOutput).toMatch(
68-
"Copying pre-rendered pages without props to out_publish/"
67+
`Setting up pages with getStaticProps and revalidation interval as Netlify Functions in out_functions${sep}`
68+
);
69+
expect(buildOutput).toMatch(
70+
`Copying pre-rendered pages without props to out_publish${sep}`
6971
);
7072
expect(buildOutput).toMatch("Setting up redirects");
7173
expect(buildOutput).toMatch("Success! All done!");
7274
});
7375
});
7476

77+
// describe("next-on-netlify", () => {
78+
// test("builds successfully", () => {
79+
// expect(buildOutput).toMatch("Next on Netlify");
80+
// expect(buildOutput).toMatch(
81+
// `Copying public${sep} folder to out_publish${sep}`
82+
// );
83+
// expect(buildOutput).toMatch("Copying static NextJS assets to out_publish/");
84+
// expect(buildOutput).toMatch(
85+
// "Setting up API endpoints as Netlify Functions in out_functions/"
86+
// );
87+
// expect(buildOutput).toMatch(
88+
// "Setting up pages with getInitialProps as Netlify Functions in out_functions/"
89+
// );
90+
// expect(buildOutput).toMatch(
91+
// "Setting up pages with getServerSideProps as Netlify Functions in out_functions/"
92+
// );
93+
// expect(buildOutput).toMatch(
94+
// "Copying pre-rendered pages with getStaticProps and JSON data to out_publish/"
95+
// );
96+
// expect(buildOutput).toMatch(
97+
// "Setting up pages with getStaticProps and fallback: true as Netlify Functions in out_functions/"
98+
// );
99+
// expect(buildOutput).toMatch(
100+
// "Setting up pages with getStaticProps and revalidation interval as Netlify Functions in out_functions/"
101+
// );
102+
// expect(buildOutput).toMatch(
103+
// "Copying pre-rendered pages without props to out_publish/"
104+
// );
105+
// expect(buildOutput).toMatch("Setting up redirects");
106+
// expect(buildOutput).toMatch("Success! All done!");
107+
// });
108+
// });
109+
75110
describe("SSR Pages", () => {
76111
const functionsDir = join(PROJECT_PATH, "out_functions");
77112

0 commit comments

Comments
 (0)