From 91eca91733cc9a4e00c7f79aa7e64f0078cc9a1b Mon Sep 17 00:00:00 2001 From: Annie Li Date: Fri, 3 Feb 2023 09:54:15 -0800 Subject: [PATCH 1/2] Lint test projects --- test/stripe.spec.ts | 9 +++++---- testProjects/cjs/.eslintrc.js | 14 ++++++++++++++ testProjects/cjs/package.json | 7 ++++++- testProjects/mjs-ts/.eslintrc.js | 17 +++++++++++++++++ testProjects/mjs-ts/index.ts | 17 ++++++++--------- testProjects/mjs-ts/package.json | 9 ++++++++- testProjects/mjs/.eslintrc.cjs | 14 ++++++++++++++ testProjects/mjs/package.json | 7 ++++++- 8 files changed, 78 insertions(+), 16 deletions(-) create mode 100644 testProjects/cjs/.eslintrc.js create mode 100644 testProjects/mjs-ts/.eslintrc.js create mode 100644 testProjects/mjs/.eslintrc.cjs diff --git a/test/stripe.spec.ts b/test/stripe.spec.ts index 6c32783574..3bdb637cf1 100644 --- a/test/stripe.spec.ts +++ b/test/stripe.spec.ts @@ -663,10 +663,11 @@ describe('Stripe Module', function() { describe('imports', function() { const runTestProject = (projectName: string): void => { const script = ` - cd testProjects/${projectName} - npm install - npm run-script runtestproject -- ${testUtils.getUserStripeKey()} - `; + cd testProjects/${projectName} && + npm install && + npm run lint && + npm run runtestproject -- ${testUtils.getUserStripeKey()} + `; require('child_process').execSync(script); }; diff --git a/testProjects/cjs/.eslintrc.js b/testProjects/cjs/.eslintrc.js new file mode 100644 index 0000000000..9771dc3687 --- /dev/null +++ b/testProjects/cjs/.eslintrc.js @@ -0,0 +1,14 @@ +module.exports = { + root: true, + env: { + node: true, + es6: true, + }, + extends: [ + 'eslint:recommended', + 'plugin:eslint-plugin-import/recommended' + ], + rules: { + 'import/no-unresolved': [2, {commonjs: true}], + } +}; diff --git a/testProjects/cjs/package.json b/testProjects/cjs/package.json index a4ef78be00..a977df6728 100644 --- a/testProjects/cjs/package.json +++ b/testProjects/cjs/package.json @@ -8,6 +8,11 @@ "stripe": "file:../../" }, "scripts": { - "runtestproject": "node index.js" + "runtestproject": "node index.js", + "lint": "eslint ." + }, + "devDependencies": { + "eslint": "^8.33.0", + "eslint-plugin-import": "^2.27.5" } } diff --git a/testProjects/mjs-ts/.eslintrc.js b/testProjects/mjs-ts/.eslintrc.js new file mode 100644 index 0000000000..b833619bcb --- /dev/null +++ b/testProjects/mjs-ts/.eslintrc.js @@ -0,0 +1,17 @@ +module.exports = { + root: true, + env: { + node: true, + es6: true, + }, + parser: '@typescript-eslint/parser', + "plugins": [ + "@typescript-eslint" + ], + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/eslint-recommended', + 'plugin:@typescript-eslint/recommended', + 'plugin:eslint-plugin-import/recommended' + ] +}; diff --git a/testProjects/mjs-ts/index.ts b/testProjects/mjs-ts/index.ts index 5789677248..1ae09ae71a 100644 --- a/testProjects/mjs-ts/index.ts +++ b/testProjects/mjs-ts/index.ts @@ -1,8 +1,9 @@ -import {Stripe} from 'stripe'; -import DefaultStripe from 'stripe'; +import DefaultStripe, {Stripe} from 'stripe'; const stripe = new Stripe(process.argv[2], {apiVersion: '2022-11-15'}); -const defaultStripe = new DefaultStripe(process.argv[2], {apiVersion: '2022-11-15'}); +const defaultStripe = new DefaultStripe(process.argv[2], { + apiVersion: '2022-11-15', +}); try { throw new stripe.errors.StripeError({ @@ -11,7 +12,7 @@ try { } as any); } catch (e) { if (e instanceof stripe.errors.StripeError) { - console.log("Caught StripeError"); + console.log('Caught StripeError'); } else { throw e; } @@ -22,17 +23,15 @@ async function exampleFunction(args: Stripe.PaymentIntentCreateParams) { const pi: Stripe.PaymentIntent = await stripe.paymentIntents.create(args); } catch (e) { if (e instanceof stripe.errors.StripeInvalidRequestError) { - console.log("Caught StripeInvalidRequestError"); + console.log('Caught StripeInvalidRequestError'); } else { throw e; } } } -exampleFunction( - //@ts-ignore - { - // The required parameter currency is missing +exampleFunction({ + currency: 'usd', amount: 2000, confirm: true, payment_method: 'pm_card_visa', diff --git a/testProjects/mjs-ts/package.json b/testProjects/mjs-ts/package.json index 3883a09409..eb7af9a233 100644 --- a/testProjects/mjs-ts/package.json +++ b/testProjects/mjs-ts/package.json @@ -8,6 +8,13 @@ "ts-node": "^10.9.1" }, "scripts": { - "runtestproject": "ts-node index.ts" + "runtestproject": "ts-node index.ts", + "lint": "eslint . --ext .ts" + }, + "devDependencies": { + "@typescript-eslint/eslint-plugin": "^5.50.0", + "@typescript-eslint/parser": "^5.50.0", + "eslint": "^8.33.0", + "eslint-plugin-import": "^2.27.5" } } diff --git a/testProjects/mjs/.eslintrc.cjs b/testProjects/mjs/.eslintrc.cjs new file mode 100644 index 0000000000..be7cd47486 --- /dev/null +++ b/testProjects/mjs/.eslintrc.cjs @@ -0,0 +1,14 @@ +module.exports = { + root: true, + env: { + node: true, + es6: true, + }, + extends: [ + 'eslint:recommended', + 'plugin:eslint-plugin-import/recommended' + ], + rules: { + 'no-unused-vars': 'off' + } +}; diff --git a/testProjects/mjs/package.json b/testProjects/mjs/package.json index 66c7af04fb..421fe4f082 100644 --- a/testProjects/mjs/package.json +++ b/testProjects/mjs/package.json @@ -8,6 +8,11 @@ "stripe": "file:../../" }, "scripts": { - "runtestproject": "node index.js" + "runtestproject": "node index.js", + "lint": "eslint ." + }, + "devDependencies": { + "eslint": "^8.33.0", + "eslint-plugin-import": "^2.27.5" } } From d1b00ce70084aa8d2ce7e8233df9102a0c1c5f48 Mon Sep 17 00:00:00 2001 From: Annie Li Date: Fri, 3 Feb 2023 11:24:27 -0800 Subject: [PATCH 2/2] Increase timeout --- test/stripe.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/stripe.spec.ts b/test/stripe.spec.ts index 3bdb637cf1..ce2540bb45 100644 --- a/test/stripe.spec.ts +++ b/test/stripe.spec.ts @@ -661,6 +661,7 @@ describe('Stripe Module', function() { }); describe('imports', function() { + this.timeout(30000); const runTestProject = (projectName: string): void => { const script = ` cd testProjects/${projectName} &&