diff --git a/.eslintignore b/.eslintignore index aaaf6b9a4c..331241cae0 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,4 @@ *.node*.js node_modules lib +testProjects diff --git a/.gitignore b/.gitignore index 9c0b948ea6..4745a3ac92 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ tags coverage .idea lib +testProjects/**/node_modules +testProjects/**/package-lock.json diff --git a/test/imports.spec.js b/test/imports.spec.js new file mode 100644 index 0000000000..0611105b4d --- /dev/null +++ b/test/imports.spec.js @@ -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(); + }); + }); +}); diff --git a/testProjects/cjs/index.js b/testProjects/cjs/index.js new file mode 100644 index 0000000000..3ae1777688 --- /dev/null +++ b/testProjects/cjs/index.js @@ -0,0 +1,5 @@ +const stripe = require('stripe')(process.argv[2]); + +stripe.customers.create({ + email: 'customer@example.com', +}); diff --git a/testProjects/cjs/package.json b/testProjects/cjs/package.json new file mode 100644 index 0000000000..0415d9242f --- /dev/null +++ b/testProjects/cjs/package.json @@ -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" + } +} diff --git a/testProjects/mjs/index.js b/testProjects/mjs/index.js new file mode 100644 index 0000000000..01d155392c --- /dev/null +++ b/testProjects/mjs/index.js @@ -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', +}); diff --git a/testProjects/mjs/package.json b/testProjects/mjs/package.json new file mode 100644 index 0000000000..0a66a1509b --- /dev/null +++ b/testProjects/mjs/package.json @@ -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" + } +}