Skip to content

Commit

Permalink
add 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
andyrichardson committed Aug 30, 2021
1 parent 73dbe81 commit 54127d8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "netlify-plugin-ttl-cache",
"version": "1.0.1",
"version": "1.0.2",
"description": "A Netlify plugin for persisting immutable build assets across releases.",
"keywords": [
"netlify",
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { stat, unlink } = require("fs").promises;
const { stat, unlink, rmdir } = require("fs").promises;
const { getDaysApart, getDirFilenames, addTrailingSlash } = require("./utils");

const TMP_CACHE_DIR = ".netlify-plugin-ttl-cache";
Expand Down Expand Up @@ -38,6 +38,7 @@ const onPostBuild = async ({ utils, inputs }) => {
addTrailingSlash(TMP_CACHE_DIR),
addTrailingSlash(inputs.path),
]);
await rmdir(TMP_CACHE_DIR, { recursive: true });
}

// Save new cache
Expand Down
16 changes: 15 additions & 1 deletion src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ jest.mock("fs", () => ({
promises: {
stat: jest.fn(),
unlink: jest.fn(),
rmdir: jest.fn(),
},
}));
jest.mock("./utils", () => ({
...jest.requireActual("./utils"),
getDirFilenames: jest.fn(),
}));
const { stat, unlink } = require("fs").promises;
const { stat, unlink, rmdir } = require("fs").promises;
const { onPreBuild, onPostBuild } = require("./index");
const { getDirFilenames } = require("./utils");

Expand Down Expand Up @@ -144,5 +145,18 @@ describe("on onPostBuild", () => {
expect(utils.cache.save).toBeCalledTimes(1);
expect(utils.cache.save).toBeCalledWith(inputs.path);
});

it("removes old cache directory", async () => {
await onPostBuild({ inputs, utils });
expect(rmdir).toBeCalledTimes(1);
expect(rmdir.mock.calls[0]).toMatchInlineSnapshot(`
Array [
".netlify-plugin-ttl-cache",
Object {
"recursive": true,
},
]
`);
});
});
});

0 comments on commit 54127d8

Please sign in to comment.