Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: skip blob tests if live #6540

Merged
merged 3 commits into from
May 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
171 changes: 91 additions & 80 deletions tests/integration/commands/dev/dev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,58 +530,66 @@ describe.concurrent('command/dev', () => {

describe.concurrent('blobs', () => {
describe.concurrent('on startup', () => {
test('seeds the blob server with files written to `.netlify/blobs/deploy` by the user', async (t) => {
await withSiteBuilder(t, async (builder) => {
const blobFixtures = [
{ key: 'test.txt', content: 'I am the first test blob', metadata: null },
{ key: 'test2.txt', content: 'I am the second test blob', metadata: null },
{ key: 'subdir/test3.txt', content: 'I am the third (nested) test blob', metadata: null },
{
key: 'subdir/deeper/test4.txt',
content: 'I am the fourth (more deeply nested) test blob',
metadata: null,
},
]
withBlobs(builder, blobFixtures)
withServeBlobsFunction(builder)

await builder.build()

await withDevServer({ cwd: builder.directory }, async (server) => {
t.expect.hasAssertions()
t.expect.assertions(blobFixtures.length * 2)
for (const { content, key } of blobFixtures) {
const res = await fetch(new URL(`/${key}`, server.url))
t.expect(res.status).toBe(200)

const body = await res.json()
t.expect(body).toHaveProperty('data', content)
}
test.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true')(
'seeds the blob server with files written to `.netlify/blobs/deploy` by the user',
async (t) => {
await withSiteBuilder(t, async (builder) => {
const blobFixtures = [
{ key: 'test.txt', content: 'I am the first test blob', metadata: null },
{ key: 'test2.txt', content: 'I am the second test blob', metadata: null },
{ key: 'subdir/test3.txt', content: 'I am the third (nested) test blob', metadata: null },
{
key: 'subdir/deeper/test4.txt',
content: 'I am the fourth (more deeply nested) test blob',
metadata: null,
},
]
withBlobs(builder, blobFixtures)
withServeBlobsFunction(builder)

await builder.build()

await withDevServer({ cwd: builder.directory }, async (server) => {
t.expect.hasAssertions()
t.expect.assertions(blobFixtures.length * 2)
for (const { content, key } of blobFixtures) {
const res = await fetch(new URL(`/${key}`, server.url))
t.expect(res.status).toBe(200)

const body = await res.json()
t.expect(body).toHaveProperty('data', content)
}
})
})
})
})

test('reads metadata files and attaches their contents to their corresponding blob', async (t) => {
await withSiteBuilder(t, async (builder) => {
const blobFixtures = [{ key: 'test.txt', content: 'I am the first test blob', metadata: { type: 'my-junk' } }]
withBlobs(builder, blobFixtures)
withServeBlobsFunction(builder)

await builder.build()

await withDevServer({ cwd: builder.directory }, async (server) => {
t.expect.hasAssertions()
t.expect.assertions(blobFixtures.length * 2)
for (const { key, metadata } of blobFixtures) {
const res = await fetch(new URL(`/${key}`, server.url))
t.expect(res.status).toBe(200)

const body = await res.json()
t.expect(body).toHaveProperty('metadata', metadata)
}
},
)

test.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true')(
'reads metadata files and attaches their contents to their corresponding blob',
async (t) => {
await withSiteBuilder(t, async (builder) => {
const blobFixtures = [
{ key: 'test.txt', content: 'I am the first test blob', metadata: { type: 'my-junk' } },
]
withBlobs(builder, blobFixtures)
withServeBlobsFunction(builder)

await builder.build()

await withDevServer({ cwd: builder.directory }, async (server) => {
t.expect.hasAssertions()
t.expect.assertions(blobFixtures.length * 2)
for (const { key, metadata } of blobFixtures) {
const res = await fetch(new URL(`/${key}`, server.url))
t.expect(res.status).toBe(200)

const body = await res.json()
t.expect(body).toHaveProperty('metadata', metadata)
}
})
})
})
})
},
)

test('does not write metadata files to the blob server', async (t) => {
await withSiteBuilder(t, async (builder) => {
Expand All @@ -599,41 +607,44 @@ describe.concurrent('command/dev', () => {
})
})

test('seeds the blob server with files written to `.netlify/blobs/deploy` by the onDev stage', async (t) => {
t.expect.hasAssertions()

await withSiteBuilder(t, async (builder) => {
withServeBlobsFunction(builder)
builder
.withBuildPlugin({
name: 'deploy-blobs',
plugin: {
async onDev() {
// eslint-disable-next-line @typescript-eslint/no-shadow, @typescript-eslint/no-var-requires, n/global-require
const fs = require('node:fs/promises')

await fs.mkdir('.netlify/blobs/deploy', { recursive: true })
await fs.writeFile(`.netlify/blobs/deploy/test.txt`, 'I am the first test blob')
test.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true')(
'seeds the blob server with files written to `.netlify/blobs/deploy` by the onDev stage',
async (t) => {
t.expect.hasAssertions()

await withSiteBuilder(t, async (builder) => {
withServeBlobsFunction(builder)
builder
.withBuildPlugin({
name: 'deploy-blobs',
plugin: {
async onDev() {
// eslint-disable-next-line @typescript-eslint/no-shadow, @typescript-eslint/no-var-requires, n/global-require
const fs = require('node:fs/promises')

await fs.mkdir('.netlify/blobs/deploy', { recursive: true })
await fs.writeFile(`.netlify/blobs/deploy/test.txt`, 'I am the first test blob')
},
},
},
})
.withNetlifyToml({
config: {
plugins: [{ package: './plugins/deploy-blobs' }],
},
})
})
.withNetlifyToml({
config: {
plugins: [{ package: './plugins/deploy-blobs' }],
},
})

await builder.build()
await builder.build()

await withDevServer({ cwd: builder.directory, debug: true }, async (server) => {
const res = await fetch(new URL(`/test.txt`, server.url))
t.expect(res.status).toBe(200)
await withDevServer({ cwd: builder.directory, debug: true }, async (server) => {
const res = await fetch(new URL(`/test.txt`, server.url))
t.expect(res.status).toBe(200)

const body = await res.json()
t.expect(body).toEqual({ data: 'I am the first test blob', metadata: {} })
const body = await res.json()
t.expect(body).toEqual({ data: 'I am the first test blob', metadata: {} })
})
})
})
})
},
)
})
})
})