File tree Expand file tree Collapse file tree 8 files changed +37
-7
lines changed
test/output-integration/browser Expand file tree Collapse file tree 8 files changed +37
-7
lines changed Original file line number Diff line number Diff line change 1
1
dist
2
2
gh-pages
3
- test /output-integration /browser /public /contentful * .js
4
3
5
4
# Esdoc dirs
6
5
out
Original file line number Diff line number Diff line change
1
+ public /contentful * .js
2
+ public /env.js
Original file line number Diff line number Diff line change 7
7
"scripts" : {
8
8
"test" : " vitest --run" ,
9
9
"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"
11
13
},
12
14
"author" : " " ,
13
15
"license" : " ISC" ,
Original file line number Diff line number Diff line change 7
7
< title > contentful-management.js Test Page</ title >
8
8
</ head >
9
9
< body >
10
+ < script src ="./env.js "> </ script >
10
11
< script src ="./contentful-management.browser.min.js "> </ script >
11
12
< script src ="./index.js "> </ script >
12
13
< div id ="content "> This text should be replaced by the response</ div >
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ async function run() {
7
7
accessToken : process . env . CONTENTFUL_INTEGRATION_TEST_CMA_TOKEN ,
8
8
} )
9
9
10
- const response = await client . getEntry ( 'nyancat ')
10
+ const response = await client . getSpace ( 'segpl12szpe6 ')
11
11
12
12
const loadedDiv = document . createElement ( 'div' )
13
13
loadedDiv . id = 'contentful-management-loaded'
Original file line number Diff line number Diff line change
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 } ` )
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import { version as packageVersion } from '../../../../package.json'
5
5
describe ( 'contentful-management.js Browser Test' , ( ) => {
6
6
it ( 'Entry has been loaded successfully' , async ( ) => {
7
7
const text = await page . $eval ( '#content' , ( el ) => el . innerHTML )
8
- expect ( text ) . toEqual ( 'nyancat ' )
8
+ expect ( text ) . toEqual ( 'segpl12szpe6 ' )
9
9
} )
10
10
11
11
it ( 'Has correct user agent version' , async ( ) => {
Original file line number Diff line number Diff line change @@ -8,8 +8,7 @@ let page: Page
8
8
9
9
beforeAll ( async ( ) => {
10
10
browser = await puppeteer . launch ( {
11
- headless : false ,
12
- product : 'firefox' ,
11
+ headless : true ,
13
12
} )
14
13
} )
15
14
@@ -21,7 +20,7 @@ beforeEach(async () => {
21
20
22
21
await page . goto ( `file:${ path . join ( __dirname , 'public/index.html' ) } ` )
23
22
24
- await page . waitForSelector ( '#contentful-loaded' , { timeout : 5_000 } )
23
+ await page . waitForSelector ( '#contentful-management- loaded' , { timeout : 5_000 } )
25
24
} )
26
25
27
26
afterAll ( async ( ) => {
You can’t perform that action at this time.
0 commit comments