Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/v0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
occar421 committed Mar 30, 2018
2 parents a6e168c + ab3736b commit 923ff30
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 32 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
build_6:
docker:
- image: circleci/node:6
working_directory: ~/
working_directory: ~/node6
steps:
- checkout

Expand All @@ -25,7 +25,7 @@ jobs:
build_8:
docker:
- image: circleci/node:8
working_directory: ~/
working_directory: ~/node8
steps:
- checkout

Expand All @@ -46,7 +46,7 @@ jobs:
deploy:
docker:
- image: circleci/node:8
working_directory: ~/
working_directory: ~/deploy
steps:
- checkout

Expand All @@ -70,5 +70,5 @@ workflows:
tags:
only: /v[0-9]+(\.[0-9]+)*/
- deploy:
retuires:
requires:
- approve
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
testEnvironment: "node"
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"name": "transmit-update-loader",
"version": "0.1.0",
"description":
"Message passing tool to transmit update to another file during webpack loader process.",
"description": "Message passing tool to transmit update to another file during webpack loader process.",
"main": "src/loader.js",
"repository": "https://github.com/occar421/transmit-update-loader",
"author": "MasuqaT <[email protected]>",
Expand All @@ -14,6 +13,7 @@
"eslint": "^4.18.2",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-prettier": "^2.6.0",
"fs-extra": "^5.0.0",
"jest": "^22.4.2",
"memory-fs": "^0.4.1",
"prettier": "^1.11.1",
Expand Down
27 changes: 13 additions & 14 deletions test/helpers.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
import fs from "fs";
import * as fs from "fs-extra";
import path from "path";
import { promisify } from "util";

/**
* @param {string} fileName
* @returns {Promise<string>}
*/
export const readFileAsync = fileName =>
promisify(fs.readFile)(path.join(__dirname, fileName)).then(b =>
b.toString()
);
fs.readFile(path.join(__dirname, fileName)).then(b => b.toString());

/**
* @param {string} fileName
* @returns {Promise<"fs".Stats>}
* @returns {Promise<{ctime:Date}>}
*/
export const fileStatAsync = fileName =>
promisify(fs.stat)(path.join(__dirname, fileName));
fs.stat(path.join(__dirname, fileName));

/**
* @param {string} dirPath
* @returns {Promise<array<string>>}
*/
const enumerateFilesAsync = dirPath =>
promisify(fs.readdir)(dirPath).then(files =>
files.map(f => path.join(dirPath, f)).filter(f => fs.statSync(f).isFile())
);
fs
.readdir(dirPath)
.then(files =>
files.map(f => path.join(dirPath, f)).filter(f => fs.statSync(f).isFile())
);

/**
* @param {string} fileName
* @returns {Promise<boolean>}
*/
export const existsAsync = fileName =>
promisify(fs.access)(path.join(__dirname, fileName))
.then(() => true)
.catch(() => false);
fs.pathExists(path.join(__dirname, fileName));

export const removeGeneratedFiles = async () => {
const files = await enumerateFilesAsync(path.join(__dirname, "fixtures"));
files.filter(f => f.endsWith(".null")).forEach(f => {
fs.unlinkSync(f);
fs.unlink(f, err => {
if (err && err.code !== "ENOENT") throw err;
});
});
};
28 changes: 17 additions & 11 deletions test/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ it("should not renew itself by default", async () => {
transmitRules: [{ test: /\/(.*$)/, targets: ["$1"] }]
}); // identity mapping
const postStat = await fileStatAsync(targetFileName);
expect(postStat.ctimeMs).toBe(preStat.ctimeMs);
expect(postStat.ctime.getTime()).toBe(preStat.ctime.getTime());
});

it("should not renew itself within multi targets", async () => {
Expand All @@ -36,7 +36,7 @@ it("should not renew itself within multi targets", async () => {
transmitRules: [{ test: /\/(.*$)/, targets: ["$1", "$1", "foo", "bar"] }]
});
const postStat = await fileStatAsync(targetFileName);
expect(postStat.ctimeMs).toBe(preStat.ctimeMs);
expect(postStat.ctime.getTime()).toBe(preStat.ctime.getTime());
});

it("should not renew itself within multi rules", async () => {
Expand All @@ -50,7 +50,7 @@ it("should not renew itself within multi rules", async () => {
]
});
const postStat = await fileStatAsync(targetFileName);
expect(postStat.ctimeMs).toBe(preStat.ctimeMs);
expect(postStat.ctime.getTime()).toBe(preStat.ctime.getTime());
});

it("should renew foo.md from foo.txt", async () => {
Expand All @@ -61,7 +61,7 @@ it("should renew foo.md from foo.txt", async () => {
transmitRules: [{ test: /(\.txt$)/, targets: [".md"] }]
});
const postStat = await fileStatAsync(targetFileName);
expect(postStat.ctimeMs).toBeGreaterThan(preStat.ctimeMs);
expect(postStat.ctime.getTime()).toBeGreaterThan(preStat.ctime.getTime());
});

it("should renew foo.md and foo.asciidoc from foo.txt", async () => {
Expand All @@ -75,8 +75,8 @@ it("should renew foo.md and foo.asciidoc from foo.txt", async () => {
});
const postStatMd = await fileStatAsync(targetMdFileName);
const postStatAd = await fileStatAsync(targetAdFileName);
expect(postStatMd.ctimeMs).toBeGreaterThan(preStatMd.ctimeMs);
expect(postStatAd.ctimeMs).toBeGreaterThan(preStatAd.ctimeMs);
expect(postStatMd.ctime.getTime()).toBeGreaterThan(preStatMd.ctime.getTime());
expect(postStatAd.ctime.getTime()).toBeGreaterThan(preStatAd.ctime.getTime());
});

it("should renew foo.md and foo.asciidoc and foo.rst from foo.txt", async () => {
Expand All @@ -93,9 +93,11 @@ it("should renew foo.md and foo.asciidoc and foo.rst from foo.txt", async () =>
const postStatMd = await fileStatAsync(targetMdFileName);
const postStatAd = await fileStatAsync(targetAdFileName);
const postStatRst = await fileStatAsync(targetRstFileName);
expect(postStatMd.ctimeMs).toBeGreaterThan(preStatMd.ctimeMs);
expect(postStatAd.ctimeMs).toBeGreaterThan(preStatAd.ctimeMs);
expect(postStatRst.ctimeMs).toBeGreaterThan(preStatRst.ctimeMs);
expect(postStatMd.ctime.getTime()).toBeGreaterThan(preStatMd.ctime.getTime());
expect(postStatAd.ctime.getTime()).toBeGreaterThan(preStatAd.ctime.getTime());
expect(postStatRst.ctime.getTime()).toBeGreaterThan(
preStatRst.ctime.getTime()
);
});

it("should renew foo.md from foo.txt and bar.txt from foo.txt", async () => {
Expand All @@ -112,8 +114,12 @@ it("should renew foo.md from foo.txt and bar.txt from foo.txt", async () => {
});
const postStatFoo = await fileStatAsync(targetFooFileName);
const postStatBar = await fileStatAsync(targetBarFileName);
expect(postStatFoo.ctimeMs).toBeGreaterThan(preStatFoo.ctimeMs);
expect(postStatBar.ctimeMs).toBeGreaterThan(preStatBar.ctimeMs);
expect(postStatFoo.ctime.getTime()).toBeGreaterThan(
preStatFoo.ctime.getTime()
);
expect(postStatBar.ctime.getTime()).toBeGreaterThan(
preStatBar.ctime.getTime()
);
});

it("should not create a new file by default", async () => {
Expand Down
20 changes: 19 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1901,6 +1901,14 @@ from2@^2.1.0:
inherits "^2.0.1"
readable-stream "^2.0.0"

fs-extra@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-5.0.0.tgz#414d0110cdd06705734d055652c5411260c31abd"
dependencies:
graceful-fs "^4.1.2"
jsonfile "^4.0.0"
universalify "^0.1.0"

fs-write-stream-atomic@^1.0.8:
version "1.0.10"
resolved "https://registry.yarnpkg.com/fs-write-stream-atomic/-/fs-write-stream-atomic-1.0.10.tgz#b47df53493ef911df75731e70a9ded0189db40c9"
Expand Down Expand Up @@ -2031,7 +2039,7 @@ globby@^5.0.0:
pify "^2.0.0"
pinkie-promise "^2.0.0"

graceful-fs@^4.1.11, graceful-fs@^4.1.2:
graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6:
version "4.1.11"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"

Expand Down Expand Up @@ -2946,6 +2954,12 @@ json5@^0.5.0, json5@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821"

jsonfile@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb"
optionalDependencies:
graceful-fs "^4.1.6"

jsonify@~0.0.0:
version "0.0.0"
resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73"
Expand Down Expand Up @@ -4629,6 +4643,10 @@ unique-slug@^2.0.0:
dependencies:
imurmurhash "^0.1.4"

universalify@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.1.tgz#fa71badd4437af4c148841e3b3b165f9e9e590b7"

unset-value@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/unset-value/-/unset-value-1.0.0.tgz#8376873f7d2335179ffb1e6fc3a8ed0dfc8ab559"
Expand Down

0 comments on commit 923ff30

Please sign in to comment.