Skip to content

Commit

Permalink
Add test projects with CommonJS and ES6 imports
Browse files Browse the repository at this point in the history
  • Loading branch information
anniel-stripe committed Sep 14, 2022
1 parent fa5918a commit 7a993ff
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.node*.js
node_modules
lib
testProjects
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ tags
coverage
.idea
lib
testProjects/**/node_modules
testProjects/**/package-lock.json
29 changes: 29 additions & 0 deletions test/imports.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* eslint-disable new-cap */

'use strict';

const testUtils = require('../testUtils');
const expect = require('chai').expect;

const runTestProject = (projectName) => {
const script = `
cd testProjects/${projectName}
npm install
node index.js ${testUtils.getUserStripeKey()}
`;
require('child_process').execSync(script);
};

describe('Stripe Module', function() {
this.timeout(20000);

describe('imports', () => {
it('should work with CommonJS imports', () => {
expect(runTestProject.bind(null, 'cjs')).to.not.throw();
});

it('should work with ESModule imports', () => {
expect(runTestProject.bind(null, 'mjs')).to.not.throw();
});
});
});
5 changes: 5 additions & 0 deletions testProjects/cjs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const stripe = require('stripe')(process.argv[2]);

stripe.customers.create({
email: 'customer@example.com',
});
13 changes: 13 additions & 0 deletions testProjects/cjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "cjs",
"type": "commonjs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"stripe": "file:../../"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
}
}
7 changes: 7 additions & 0 deletions testProjects/mjs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Stripe from 'stripe';

const stripe = new Stripe(process.argv[2]);

const customer = await stripe.customers.create({
email: 'customer@example.com',
});
13 changes: 13 additions & 0 deletions testProjects/mjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "mjs",
"type": "module",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"stripe": "file:../../"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
}
}

0 comments on commit 7a993ff

Please sign in to comment.