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 3d63ada
Show file tree
Hide file tree
Showing 7 changed files with 65 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
24 changes: 24 additions & 0 deletions test/stripe.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,4 +613,28 @@ describe('Stripe Module', function() {
expect(newStripe.VERSION).to.equal(Stripe.PACKAGE_VERSION);
});
});

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

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

it('should work with ESModule imports', function() {
// Node supports ES Modules starting at v12
if (parseInt(process.versions.node.split('.')[0], 10) <= 12) {
this.skip();
}

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]);

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 3d63ada

Please sign in to comment.