Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions retail/interactive-tutorials/product/crud-product.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,16 @@ async function main(generatedProductId) {
};

console.log('Start CRUD product');
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
// Create product
console.log('Start to create the product');
const createdProduct = await callCreateProduct();
console.log(`Product ${createdProduct.id} creation finished`);

// Wait for the product to be available for read operations
const API_PROPAGATION_DELAY_MS = 30000; // 30 seconds
await delay(API_PROPAGATION_DELAY_MS);

// Get product
console.log('Start product get operation');
const foundProduct = await callGetProduct();
Expand Down
5 changes: 5 additions & 0 deletions retail/interactive-tutorials/product/get-product.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ async function main(generatedProductId) {
// Imports the Google Cloud client library.
const {ProductServiceClient} = require('@google-cloud/retail').v2;
const utils = require('../setup/setup-cleanup');
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));

// Instantiates a client.
const retailClient = new ProductServiceClient();
Expand All @@ -27,6 +28,10 @@ async function main(generatedProductId) {
// Create product
const product = await utils.createProduct(projectId, generatedProductId);

// Wait for the product to be available for read operations
const API_PROPAGATION_DELAY_MS = 30000; // 30 seconds
await delay(API_PROPAGATION_DELAY_MS);

// Full resource name of Product
const name = product.name;

Expand Down
5 changes: 5 additions & 0 deletions retail/interactive-tutorials/test/crud-product.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ describe('CRUD product', () => {

after(async () => {
try {
// Allow brief propagation time for product deletion
const API_PROPAGATION_DELAY_MS = 30000; // 30 seconds
await new Promise(resolve =>
setTimeout(resolve, API_PROPAGATION_DELAY_MS)
);
const product = await retailClient.getProduct({name: name});
expect(product, 'The product not deleted').to.be.undefined;
} catch (err) {
Expand Down
5 changes: 5 additions & 0 deletions retail/interactive-tutorials/test/get-product.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ describe('Get product', () => {

after(async () => {
try {
// Allow brief propagation time for product deletion
const API_PROPAGATION_DELAY_MS = 30000; // 30 seconds
await new Promise(resolve =>
setTimeout(resolve, API_PROPAGATION_DELAY_MS)
);
const product = await retailClient.getProduct({name: name});
expect(product, 'The product not deleted').to.be.undefined;
} catch (err) {
Expand Down
15 changes: 6 additions & 9 deletions retail/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,22 @@
"license": "Apache-2.0",
"author": "Google LLC",
"engines": {
"node": ">=16.0.0"
"node": ">=20.0.0"
},
"files": [
"*.js"
],
"scripts": {
"test": "c8 mocha -p -j 2"
},
"engines": {
"node": ">=16.0.0"
},
"dependencies": {
"@google-cloud/bigquery": "^7.0.0",
"@google-cloud/retail": "^3.0.0",
"@google-cloud/storage": "^7.0.0"
"@google-cloud/bigquery": "^8.3.1",
"@google-cloud/retail": "^4.0.0",
"@google-cloud/storage": "^8.0.0"
},
"devDependencies": {
"c8": "^10.0.0",
"chai": "^4.5.0",
"c8": "^12.0.0",
"chai": "^6.0.0",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Chai v5 and above are ESM-only. Since this project uses CommonJS (require), upgrading to chai v6.0.0 will cause tests to fail with ERR_REQUIRE_ESM. It is recommended to keep chai at ^4.5.0 to maintain compatibility.

Suggested change
"chai": "^6.0.0",
"chai": "^4.5.0",

"mocha": "^10.2.0"
}
}
Loading