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

Lint test projects #1673

Merged
merged 3 commits into from
Feb 3, 2023
Merged
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
10 changes: 6 additions & 4 deletions test/stripe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,12 +661,14 @@ describe('Stripe Module', function() {
});

describe('imports', function() {
this.timeout(30000);
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);
};

Expand Down
14 changes: 14 additions & 0 deletions testProjects/cjs/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -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}],
}
};
7 changes: 6 additions & 1 deletion testProjects/cjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
17 changes: 17 additions & 0 deletions testProjects/mjs-ts/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -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'
]
};
17 changes: 8 additions & 9 deletions testProjects/mjs-ts/index.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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;
}
Expand All @@ -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',
Expand Down
9 changes: 8 additions & 1 deletion testProjects/mjs-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
14 changes: 14 additions & 0 deletions testProjects/mjs/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -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'
}
};
7 changes: 6 additions & 1 deletion testProjects/mjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}