From a6cb120bd450bb733e8d00b0f63c4cb6ac8d05b2 Mon Sep 17 00:00:00 2001 From: Chris Breiding Date: Wed, 1 Aug 2018 09:50:20 -0400 Subject: [PATCH] add simple e2e test --- .gitignore | 1 + __snapshots__/e2e_spec.js | 16 ++++++++++++++++ package.json | 9 ++++++--- test/e2e/e2e_spec.js | 21 +++++++++++++++++++++ test/e2e/output.js | 0 test/fixtures/example_spec.js | 6 ++++++ test/{ => unit}/index_spec.js | 4 ++-- 7 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 __snapshots__/e2e_spec.js create mode 100644 test/e2e/e2e_spec.js create mode 100644 test/e2e/output.js create mode 100644 test/fixtures/example_spec.js rename test/{ => unit}/index_spec.js (99%) diff --git a/.gitignore b/.gitignore index 625212a..a903a41 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules/ .DS_Store npm-debug.log +_test-output diff --git a/__snapshots__/e2e_spec.js b/__snapshots__/e2e_spec.js new file mode 100644 index 0000000..2cf54c2 --- /dev/null +++ b/__snapshots__/e2e_spec.js @@ -0,0 +1,16 @@ +exports['browserify preprocessor - e2e correctly preprocesses the file 1'] = ` +(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i {} + + beforeEach(function () { + fs.removeSync(path.join(__dirname, '_test-output')) + }) + + it('correctly preprocesses the file', function () { + const filePath = path.join(__dirname, '..', 'fixtures', 'example_spec.js') + const outputPath = path.join(__dirname, '..', '_test-output', 'output.js') + return preprocessor()({ filePath, outputPath, on }).then(() => { + snapshot(fs.readFileSync(outputPath).toString()) + }) + }) +}) diff --git a/test/e2e/output.js b/test/e2e/output.js new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/example_spec.js b/test/fixtures/example_spec.js new file mode 100644 index 0000000..97bbc0a --- /dev/null +++ b/test/fixtures/example_spec.js @@ -0,0 +1,6 @@ +it('is a test', () => { + const [a, b] = [1, 2] + expect(a).to.equal(1) + expect(b).to.equal(2) + expect(Math.min(...[3, 4])).to.equal(3) +}) diff --git a/test/index_spec.js b/test/unit/index_spec.js similarity index 99% rename from test/index_spec.js rename to test/unit/index_spec.js index 2d1fc91..71e78ba 100644 --- a/test/index_spec.js +++ b/test/unit/index_spec.js @@ -20,8 +20,8 @@ const streamApi = { } streamApi.on = sandbox.stub().returns(streamApi) -const fs = require('../fs') -const preprocessor = require('../index') +const fs = require('../../fs') +const preprocessor = require('../../index') describe('browserify preprocessor', function () { beforeEach(function () {