Skip to content

Commit

Permalink
fix: update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tractorcow committed Jul 25, 2023
1 parent 2b9f266 commit 35b0e43
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 84 deletions.
1 change: 0 additions & 1 deletion examples/with-redirects/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module.exports = {
bucketName: process.env.GATSBY_S3_TARGET_BUCKET || 'test',
bucketPrefix: process.env.GATSBY_S3_BUCKET_PREFIX ? process.env.GATSBY_S3_BUCKET_PREFIX : null,
region: process.env.AWS_REGION || 'us-east-1',
generateRedirectObjectsForPermanentRedirects: !process.env.GATSBY_S3_LEGACY_REDIRECTS,
...(process.env.GATSBY_S3_ACL
? {
acl: process.env.ACL !== 'NULL' ? process.env.ACL : null,
Expand Down
2 changes: 1 addition & 1 deletion examples/with-redirects/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exports.createPages = ({ actions }) => {

actions.createRedirect({
fromPath: '/trailing-slash/',
toPath: '/trailing-slash/1',
toPath: '/trailing-slash/1/',
isPermanent: true
});
};
Expand Down
89 changes: 7 additions & 82 deletions gatsby-plugin-s3-e2e-tests/src/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,11 @@ describe('gatsby-plugin-s3', () => {
});
});

describe('object-based redirects', () => {
describe('website redirects', () => {
const siteDirectory = getPackageDirectory('gatsby-plugin-s3-example-with-redirects');
beforeAll(async () => {
await buildSite('gatsby-plugin-s3-example-with-redirects', {
GATSBY_S3_TARGET_BUCKET: bucketName,
GATSBY_S3_LEGACY_REDIRECTS: EnvironmentBoolean.False,
});
await deploySite('gatsby-plugin-s3-example-with-redirects', [
Permission.PutObject,
Expand Down Expand Up @@ -224,8 +223,8 @@ describe('object-based redirects', () => {
},
{
name: 'temporarily',
source: '/hello-there',
expectedDestination: '/client-only',
source: '/hello-there/',
expectedDestination: `${ testingEndpoint }/client-only`,
expectedResponseCode: 302,
},
{
Expand All @@ -234,22 +233,16 @@ describe('object-based redirects', () => {
expectedDestination: '/blog/1/',
expectedResponseCode: 301,
},
{
name: 'client-only routes',
source: '/client-only/test',
expectedDestination: '/client-only',
expectedResponseCode: 302,
},
{
name: 'from a path containing special characters',
source: "/asdf123.-~_!%24%26'()*%2B%2C%3B%3D%3A%40%25",
expectedDestination: '/special-characters',
expectedDestination: '/special-characters/',
expectedResponseCode: 301,
},
{
name: 'from a path with a trailing slash',
source: '/trailing-slash/',
expectedDestination: '/trailing-slash/1',
expectedDestination: '/trailing-slash/1/',
expectedResponseCode: 301,
},
];
Expand All @@ -266,74 +259,6 @@ describe('object-based redirects', () => {
});
});

describe('rules-based redirects', () => {
beforeAll(async () => {
await buildSite('gatsby-plugin-s3-example-with-redirects', {
GATSBY_S3_TARGET_BUCKET: bucketName,
GATSBY_S3_LEGACY_REDIRECTS: EnvironmentBoolean.True,
});
await deploySite('gatsby-plugin-s3-example-with-redirects', [
Permission.CreateBucket,
Permission.PutObject,
Permission.PutObjectAcl,
Permission.PutBucketAcl,
Permission.PutBucketWebsite,
Permission.PutBucketPublicAccessBlock,
Permission.DeleteObject,
]);
});

const redirectTests = [
{
name: 'from root',
source: '/',
expectedDestination: '/page-2',
expectedResponseCode: 301,
},
{
name: 'temporarily',
source: '/hello-there',
expectedDestination: '/client-only',
expectedResponseCode: 302,
},
{
name: 'to a child directory',
source: '/blog',
expectedDestination: '/blog/1',
expectedResponseCode: 301,
},
{
name: 'client-only routes',
source: '/client-only/test',
expectedDestination: '/client-only',
expectedResponseCode: 302,
},
{
name: 'from a path containing special characters',
source: "/asdf123.-~_!%24%26'()*%2B%2C%3B%3D%3A%40%25",
expectedDestination: '/special-characters',
expectedResponseCode: 301,
},
{
name: 'from a path with a trailing slash',
source: '/trailing-slash/',
expectedDestination: '/trailing-slash/1',
expectedResponseCode: 301,
},
];

redirectTests.forEach(t => {
test(`can redirect ${ t.name }`, async () => {
const url = `${ testingEndpoint }${ t.source }`;
const response = await getUrl(url);
expect(response.status, `Incorrect response status for ${ url }`).toBe(t.expectedResponseCode);
expect(response.headers.location, `Incorrect Content-Type for ${ url }`).toBe(
`${ testingEndpoint }${ t.expectedDestination }`
);
});
});
});

describe('with pathPrefix', () => {
beforeAll(async () => {
await buildSite('gatsby-plugin-s3-example-with-redirects', {
Expand All @@ -355,13 +280,13 @@ describe('with pathPrefix', () => {
const headerTests = [
{
name: 'html files',
path: '/prefixed/page-2',
path: '/prefixed/page-2/',
cacheControl: 'public, max-age=0, must-revalidate',
contentType: 'text/html',
},
{
name: 'page-data files',
path: '/prefixed/page-data/index/page-data.json',
path: '/prefixed/page-data/page-2/page-data.json',
cacheControl: 'public, max-age=0, must-revalidate',
contentType: 'application/json',
},
Expand Down

0 comments on commit 35b0e43

Please sign in to comment.