Skip to content

Commit 0432433

Browse files
committed
test: fix output integration tests
1 parent c5aad3c commit 0432433

File tree

8 files changed

+37
-7
lines changed

8 files changed

+37
-7
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
dist
22
gh-pages
3-
test/output-integration/browser/public/contentful*.js
43

54
# Esdoc dirs
65
out
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
public/contentful*.js
2+
public/env.js

test/output-integration/browser/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"scripts": {
88
"test": "vitest --run",
99
"dev": "npx serve public",
10-
"preinstall": "cp ../../../dist/contentful-management.browser.min.js ./public/."
10+
"preinstall": "npm run preinstall:bundle && npm run preinstall:env",
11+
"preinstall:bundle": "cp ../../../dist/contentful-management.browser.min.js ./public/.",
12+
"preinstall:env": "node scripts/inject-env.js"
1113
},
1214
"author": "",
1315
"license": "ISC",

test/output-integration/browser/public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<title>contentful-management.js Test Page</title>
88
</head>
99
<body>
10+
<script src="./env.js"></script>
1011
<script src="./contentful-management.browser.min.js"></script>
1112
<script src="./index.js"></script>
1213
<div id="content">This text should be replaced by the response</div>

test/output-integration/browser/public/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ async function run() {
77
accessToken: process.env.CONTENTFUL_INTEGRATION_TEST_CMA_TOKEN,
88
})
99

10-
const response = await client.getEntry('nyancat')
10+
const response = await client.getSpace('segpl12szpe6')
1111

1212
const loadedDiv = document.createElement('div')
1313
loadedDiv.id = 'contentful-management-loaded'
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import fs from 'fs'
2+
import { resolve } from 'path'
3+
import * as url from 'url'
4+
5+
// Define the path for the output file
6+
const outputPath = resolve(
7+
url.fileURLToPath(new URL('.', import.meta.url)),
8+
'..',
9+
'public',
10+
'env.js'
11+
)
12+
13+
// Convert process.env into a JS object with JSON.stringify
14+
const envVariables = Object.keys(process.env).reduce((acc, key) => {
15+
acc[key] = process.env[key]
16+
return acc
17+
}, {})
18+
19+
// Write the JS file that exports the environment variables
20+
const fileContent = `
21+
// Auto-generated file for exposing environment variables (testing purposes only - do not do this in production)
22+
const process = { env: ${JSON.stringify(envVariables, null, 2)} };
23+
`
24+
25+
fs.writeFileSync(outputPath, fileContent, 'utf8')
26+
27+
console.log(`Environment variables written to ${outputPath}`)

test/output-integration/browser/test/index.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { version as packageVersion } from '../../../../package.json'
55
describe('contentful-management.js Browser Test', () => {
66
it('Entry has been loaded successfully', async () => {
77
const text = await page.$eval('#content', (el) => el.innerHTML)
8-
expect(text).toEqual('nyancat')
8+
expect(text).toEqual('segpl12szpe6')
99
})
1010

1111
it('Has correct user agent version', async () => {

test/output-integration/browser/vitest.setup.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ let page: Page
88

99
beforeAll(async () => {
1010
browser = await puppeteer.launch({
11-
headless: false,
12-
product: 'firefox',
11+
headless: true,
1312
})
1413
})
1514

@@ -21,7 +20,7 @@ beforeEach(async () => {
2120

2221
await page.goto(`file:${path.join(__dirname, 'public/index.html')}`)
2322

24-
await page.waitForSelector('#contentful-loaded', { timeout: 5_000 })
23+
await page.waitForSelector('#contentful-management-loaded', { timeout: 5_000 })
2524
})
2625

2726
afterAll(async () => {

0 commit comments

Comments
 (0)