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

Commit db05c51

Browse files
committed
fix previously commented out failing dataRoute tests
1 parent acc13c9 commit db05c51

File tree

6 files changed

+25
-21
lines changed

6 files changed

+25
-21
lines changed

cypress/integration/i18n_spec.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ describe("getServerSideProps", () => {
207207
failOnStatusCode: false,
208208
}).then((response) => {
209209
expect(response.status).to.eq(404);
210-
console.log("RESSSPONSEEEE", response.status, response.body);
211210
cy.state("document").write(response.body);
212211
});
213212

@@ -381,8 +380,7 @@ describe("getStaticProps", () => {
381380
cy.get("h1").should("contain", "Show #75");
382381
cy.get("p").should("contain", "The Mindy Project");
383382

384-
// fails in this test
385-
// cy.window().should("have.property", "noReload", true);
383+
cy.window().should("have.property", "noReload", true);
386384
});
387385
});
388386

@@ -418,8 +416,7 @@ describe("getStaticProps", () => {
418416
cy.get("h1").should("contain", "Show #4");
419417
cy.get("p").should("contain", "Arrow");
420418

421-
// fails with this test
422-
// cy.window().should("have.property", "noReload", true);
419+
cy.window().should("have.property", "noReload", true);
423420
});
424421
});
425422
});
@@ -466,8 +463,7 @@ describe("getStaticProps", () => {
466463
cy.get("h1").should("contain", "Show #75");
467464
cy.get("p").should("contain", "The Mindy Project");
468465

469-
// fails in this test
470-
// cy.window().should("have.property", "noReload", true);
466+
cy.window().should("have.property", "noReload", true);
471467
});
472468
});
473469
});

lib/pages/getStaticProps/setup.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ const setup = ({ functionsPath, publishPath }) => {
3232
if (nextConfig.i18n && !isDynamic) {
3333
const { locales = [] } = nextConfig.i18n;
3434

35-
// QUESTION / TO-DO:
36-
// This logic can technically be wrong if the locale isn't included in getStaticPaths
3735
locales.forEach((locale) => {
3836
// Remove extra slash for static index route
3937
// This path will go from / -> /en or /some/path -> /en/some/path

lib/pages/getStaticPropsWithFallback/redirects.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
const { join } = require("path");
22
const getFilePathForRoute = require("../../helpers/getFilePathForRoute");
33
const getNetlifyFunctionName = require("../../helpers/getNetlifyFunctionName");
4+
const getDataRouteForRoute = require("../../helpers/getDataRouteForRoute");
5+
const nextConfig = require("../../helpers/getNextConfig")();
46
const pages = require("./pages");
57

8+
const { i18n } = nextConfig;
9+
610
const redirects = [];
711

812
pages.forEach(({ route, dataRoute }) => {
@@ -17,8 +21,9 @@ pages.forEach(({ route, dataRoute }) => {
1721
});
1822

1923
// Add one redirect for the data route
24+
// If i18n, the dataRoute is under the defaultLocale
2025
redirects.push({
21-
route: dataRoute,
26+
route: i18n ? getDataRouteForRoute(route, i18n.defaultLocale) : dataRoute,
2227
target: `/.netlify/functions/${functionName}`,
2328
});
2429
});

lib/pages/getStaticPropsWithRevalidate/redirects.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pages.forEach(({ route, srcRoute, dataRoute }) => {
3232
const target = `/.netlify/functions/${functionName}`;
3333

3434
if (nextConfig.i18n) {
35-
const { locales = [] } = nextConfig.i18n;
35+
const { defaultLocale, locales = [] } = nextConfig.i18n;
3636
const isDynamic = !!srcRoute;
3737
if (!isDynamic) {
3838
// As explained in getStaticProps/setup.js, these page types that are not
@@ -65,7 +65,7 @@ pages.forEach(({ route, srcRoute, dataRoute }) => {
6565
target,
6666
});
6767
redirects.push({
68-
route: dataRoute,
68+
route: getDataRouteForRoute(srcRoute, defaultLocale),
6969
target,
7070
});
7171
i18nSrcRouteRedirectsAdded.push(srcRoute);

tests/__snapshots__/i18n.test.js.snap

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ exports[`Routing creates Netlify redirects 1`] = `
44
"# Next-on-Netlify Redirects
55
/ /.netlify/functions/next_index 200
66
/404 /en/404.html 200
7+
/_next/data/%BUILD_ID%/en/getServerSideProps/all.json /.netlify/functions/next_getServerSideProps_all_slug 200
8+
/_next/data/%BUILD_ID%/en/getServerSideProps/all/* /.netlify/functions/next_getServerSideProps_all_slug 200
9+
/_next/data/%BUILD_ID%/en/getServerSideProps/static.json /.netlify/functions/next_getServerSideProps_static 200
10+
/_next/data/%BUILD_ID%/en/getServerSideProps/:id.json /.netlify/functions/next_getServerSideProps_id 200
711
/_next/data/%BUILD_ID%/en/getStaticProps/1.json /.netlify/functions/next_getStaticProps_id 200! Cookie=__prerender_bypass,__next_preview_data
812
/_next/data/%BUILD_ID%/en/getStaticProps/2.json /.netlify/functions/next_getStaticProps_id 200! Cookie=__prerender_bypass,__next_preview_data
913
/_next/data/%BUILD_ID%/en/getStaticProps/static.json /.netlify/functions/next_getStaticProps_static 200! Cookie=__prerender_bypass,__next_preview_data
@@ -12,16 +16,20 @@ exports[`Routing creates Netlify redirects 1`] = `
1216
/_next/data/%BUILD_ID%/en/getStaticProps/withFallback/4.json /.netlify/functions/next_getStaticProps_withFallback_id 200! Cookie=__prerender_bypass,__next_preview_data
1317
/_next/data/%BUILD_ID%/en/getStaticProps/withFallback/my/path/1.json /.netlify/functions/next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data
1418
/_next/data/%BUILD_ID%/en/getStaticProps/withFallback/my/path/2.json /.netlify/functions/next_getStaticProps_withFallback_slug 200! Cookie=__prerender_bypass,__next_preview_data
15-
/_next/data/%BUILD_ID%/en/getStaticProps/withRevalidate/1.json /.netlify/functions/next_getStaticProps_withRevalidate_id 200
19+
/_next/data/%BUILD_ID%/en/getStaticProps/withFallback/:id.json /.netlify/functions/next_getStaticProps_withFallback_id 200
20+
/_next/data/%BUILD_ID%/en/getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200
21+
/_next/data/%BUILD_ID%/en/getStaticProps/withRevalidate/withFallback/:id.json /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200
22+
/_next/data/%BUILD_ID%/en/getStaticProps/withRevalidate/:id.json /.netlify/functions/next_getStaticProps_withRevalidate_id 200
23+
/_next/data/%BUILD_ID%/es/getServerSideProps/all.json /.netlify/functions/next_getServerSideProps_all_slug 200
24+
/_next/data/%BUILD_ID%/es/getServerSideProps/all/* /.netlify/functions/next_getServerSideProps_all_slug 200
25+
/_next/data/%BUILD_ID%/es/getServerSideProps/static.json /.netlify/functions/next_getServerSideProps_static 200
26+
/_next/data/%BUILD_ID%/es/getServerSideProps/:id.json /.netlify/functions/next_getServerSideProps_id 200
1627
/_next/data/%BUILD_ID%/es/getStaticProps/static.json /.netlify/functions/next_getStaticProps_static 200! Cookie=__prerender_bypass,__next_preview_data
1728
/_next/data/%BUILD_ID%/es/getStaticProps/with-revalidate.json /.netlify/functions/next_getStaticProps_withrevalidate 200
1829
/_next/data/%BUILD_ID%/getServerSideProps/all.json /.netlify/functions/next_getServerSideProps_all_slug 200
1930
/_next/data/%BUILD_ID%/getServerSideProps/all/* /.netlify/functions/next_getServerSideProps_all_slug 200
2031
/_next/data/%BUILD_ID%/getServerSideProps/static.json /.netlify/functions/next_getServerSideProps_static 200
2132
/_next/data/%BUILD_ID%/getServerSideProps/:id.json /.netlify/functions/next_getServerSideProps_id 200
22-
/_next/data/%BUILD_ID%/getStaticProps/withFallback/:id.json /.netlify/functions/next_getStaticProps_withFallback_id 200
23-
/_next/data/%BUILD_ID%/getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200
24-
/_next/data/%BUILD_ID%/getStaticProps/withRevalidate/withFallback/:id.json /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200
2533
/api/shows/:id /.netlify/functions/next_api_shows_id 200
2634
/api/shows/:params/* /.netlify/functions/next_api_shows_params 200
2735
/api/static /.netlify/functions/next_api_static 200
@@ -49,10 +57,8 @@ exports[`Routing creates Netlify redirects 1`] = `
4957
/getServerSideProps/:id /.netlify/functions/next_getServerSideProps_id 200
5058
/getStaticProps/static /en/getStaticProps/static 200
5159
/getStaticProps/with-revalidate /.netlify/functions/next_getStaticProps_withrevalidate 200
52-
/getStaticProps/withFallback/:id /en/getStaticProps/withFallback/:id 200
53-
/getStaticProps/withFallback/:id /en/getStaticProps/withFallback/:id 200
54-
/getStaticProps/withFallback/:slug/* /en/getStaticProps/withFallback/:...slug 200
55-
/getStaticProps/withFallback/:slug/* /en/getStaticProps/withFallback/:...slug 200
60+
/getStaticProps/withFallback/:id /.netlify/functions/next_getStaticProps_withFallback_id 200
61+
/getStaticProps/withFallback/:slug/* /.netlify/functions/next_getStaticProps_withFallback_slug 200
5662
/getStaticProps/withRevalidate/withFallback/:id /.netlify/functions/next_getStaticProps_withRevalidate_withFallback_id 200
5763
/getStaticProps/withRevalidate/:id /.netlify/functions/next_getStaticProps_withRevalidate_id 200
5864
/getStaticProps/:id /en/getStaticProps/:id 200

tests/i18n.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ describe("API Pages", () => {
132132

133133
describe("SSG Pages with getStaticProps", () => {
134134
test("creates pre-rendered HTML file in output directory", () => {
135-
const defaultLocale = "en";
136135
const OUTPUT_PATH = join(PROJECT_PATH, "out_publish", DEFAULT_LOCALE);
137136

138137
expect(existsSync(join(OUTPUT_PATH, "getStaticProps", "static.html"))).toBe(

0 commit comments

Comments
 (0)