Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Jun 19, 2022
1 parent 4d3f2af commit c841f43
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/core/integration-tests/test/babel.js
@@ -1,5 +1,6 @@
// @flow
import assert from 'assert';
import invariant from 'assert';
import path from 'path';
import {
bundle,
Expand Down Expand Up @@ -415,6 +416,35 @@ describe('babel', function () {
assert(distFile.includes('something different'));
});

it('should rebuild when declared external dependencies change', async function () {
let inputDir = tempy.directory();
let filepath = path.join(inputDir, 'file.txt');

await fs.ncp(
path.join(__dirname, 'integration/babel-external-deps'),
inputDir,
);

let b = bundler(path.join(inputDir, 'index.js'), {
outputFS: fs,
shouldAutoInstall: true,
});

subscription = await b.watch();
let build = await getNextBuild(b);
invariant(build.type === 'buildSuccess');
let distFile = await fs.readFile(path.join(distDir, 'index.js'), 'utf8');
assert(distFile.includes('foo'));
assert(!distFile.includes('bar'));

await fs.writeFile(filepath, 'bar');
build = await getNextBuild(b);
invariant(build.type === 'buildSuccess');
distFile = await fs.readFile(path.join(distDir, 'index.js'), 'utf8');
assert(distFile.includes('bar'));
assert(!distFile.includes('foo'));
});

it('should invalidate babel.config.js across runs', async function () {
let dateRe = /return (\d+);/;

Expand Down
@@ -0,0 +1,3 @@
{
"plugins": [["./plugin.js", { "filename": "file.txt" }]]
}
@@ -0,0 +1 @@
foo
@@ -0,0 +1 @@
console.log(REPLACE_ME);
@@ -0,0 +1,4 @@
{
"name": "babel-external-deps",
"version": "1.0.0"
}
@@ -0,0 +1,21 @@
const fs = require("fs");
const path = require("path");

module.exports = function (api, { filename }) {
const { types: t } = api;

const filepath = path.join(__dirname, filename);
const contents = fs.readFileSync(filepath, "utf8");
api.cache.never();
api.addExternalDependency(filepath);

return {
visitor: {
Identifier(path) {
if (path.node.name === "REPLACE_ME") {
path.replaceWith(t.stringLiteral(contents));
}
},
},
};
};
Empty file.

0 comments on commit c841f43

Please sign in to comment.