Compare commits
124 Commits
Author | SHA1 | Date |
---|---|---|
dependabot[bot] | 4f4015a4f7 | |
dependabot[bot] | b73ce7bd2e | |
David Humphrey | 3279c2d65a | |
Ben Heidemann | e135305f25 | |
David Humphrey | 0b26979839 | |
Ben Heidemann | 7efc4cdc1d | |
David Humphrey | 4112d072b5 | |
David Humphrey | ee26394ead | |
David Humphrey | 9f8804f716 | |
David Humphrey | 621b6567e0 | |
David Humphrey | 4acd064a2b | |
David Humphrey | b283023286 | |
Arun Bose | 24697a3ed9 | |
dependabot[bot] | 5f872f0f24 | |
bcheidemann | 77abca991a | |
bcheidemann | 49ace4b2fb | |
bcheidemann | d055d8042e | |
bcheidemann | 576831370f | |
bcheidemann | 594ab2621f | |
Ben Heidemann | 75a2cc86cf | |
Ben Heidemann | a4b3726520 | |
Ben Heidemann | 21e7a4750a | |
Ben Heidemann | aa2df3a17c | |
Ben Heidemann | bd15462f6e | |
Ben Heidemann | 78ae19fbad | |
Ben Heidemann | b3caddcfec | |
Ben Heidemann | 11e05e131b | |
Ben Heidemann | fb100b165a | |
Ben Heidemann | e94543471b | |
Ben Heidemann | 20d4d5e720 | |
Ben Heidemann | 0295d19a7f | |
Ben Heidemann | 365a7d23a3 | |
Ben Heidemann | ea5e48b48b | |
Ben Heidemann | e82374ae2b | |
Ben Heidemann | 5bd05287d4 | |
Ben Heidemann | 1c34abf009 | |
Ben Heidemann | 8b4b0a6140 | |
Ben Heidemann | e489409b9c | |
Ben Heidemann | 0db08e31bb | |
Ben Heidemann | 1f02edf5b3 | |
Ben Heidemann | 708c84fc63 | |
Ben Heidemann | 4e45701b51 | |
Ben Heidemann | fe9ed6a648 | |
Ben Heidemann | 81ab65b95c | |
Ben Heidemann | 582352f754 | |
Ben Heidemann | 3b9fafc53e | |
Ben Heidemann | bfb50bf608 | |
Ben Heidemann | ce56539190 | |
Ben Heidemann | 0f812fc6a0 | |
Ben Heidemann | 767c83706b | |
Ben Heidemann | 6a20ac2c3f | |
Ben Heidemann | 2bcf7e560b | |
Ben Heidemann | d040763a73 | |
Ben Heidemann | fd90f32d4c | |
dependabot[bot] | e18104a60d | |
Ben Heidemann | 7bd6e5f4e1 | |
Ben Heidemann | 90db749ee5 | |
Ben Heidemann | f9c5473c49 | |
Ben Heidemann | f5ad682fd7 | |
Ben Heidemann | 7b1c3e85ce | |
Ben Heidemann | 51afeeaf54 | |
Ben Heidemann | cef6adfc37 | |
Ben Heidemann | 6590cb79bd | |
Ben Heidemann | 3e88aeca92 | |
Ben Heidemann | f8c9732be9 | |
David Humphrey | 200171d2a5 | |
David Humphrey | 095f78498f | |
David Humphrey | 5cf2495079 | |
David Humphrey | aacc8061cf | |
Ben Heidemann | c378288819 | |
Ben Heidemann | d1054753a6 | |
bcheidemann | 887ed9318a | |
Ben Heidemann | ce076729f6 | |
bcheidemann | a2151cab25 | |
bcheidemann | 3a8a59d362 | |
bcheidemann | 15be384940 | |
bcheidemann | 6027376efa | |
bcheidemann | 8b57d299f4 | |
bcheidemann | d6b29226aa | |
bcheidemann | da65e06e3c | |
bcheidemann | aa152955b5 | |
bcheidemann | d264113e0d | |
bcheidemann | ce809c4ac9 | |
dependabot[bot] | 3061328459 | |
David Humphrey | c0a41d67ff | |
David Humphrey | 4941d10e13 | |
David Humphrey | 07a00a3f77 | |
bcheidemann | 0f5fe64ae8 | |
bcheidemann | 7ec1fed51f | |
bcheidemann | a2f7ee044b | |
bcheidemann | 7415e45867 | |
bcheidemann | 986ad37597 | |
bcheidemann | 9c669564b2 | |
bcheidemann | 9d03788c1c | |
Ben Heidemann | a60d2b4cfc | |
bcheidemann | 417a4e97dd | |
bcheidemann | 4d4b6bf3f3 | |
bcheidemann | f12f01dca0 | |
bcheidemann | 128e10dc13 | |
bcheidemann | ceed84f377 | |
bcheidemann | 2a581726c6 | |
David Humphrey | 75f2a70c7b | |
David Humphrey | 9db879374d | |
David Humphrey | 98683fe261 | |
SillyFreak | f1fc53d88f | |
Rachael Scotchmer | 4aae53839a | |
dcoull | 94d5ff8795 | |
Charles M Drani | ee56794601 | |
rscotchmer | 914ba8b473 | |
Oleksii Polovyi | 2a4fa0f0fd | |
ApolllonDev | 9d3f220d92 | |
Abdirahman Guled | 3d10d6431c | |
Adel El Masery | 7ab6f5e7c6 | |
kwchan19 | 9487e8ecc6 | |
hoaianhkhang | e6f8ef2251 | |
Paul Moon | f2201e7a74 | |
otkach | 3447ec9c8a | |
David Humphrey (:humph) david.humphrey@senecacollege.ca | fe17870a8f | |
David Humphrey | f4e0dce8d3 | |
Priyanka Dhiman | 34e5580a66 | |
Aqeel Parpia | c515865fb3 | |
Aqeel Parpia | 4887cc725f | |
Aqeel Parpia | 3471848b39 | |
Priyanka Dhiman | 7cdef6d963 |
|
@ -0,0 +1 @@
|
|||
* text=auto eol=lf
|
|
@ -0,0 +1,27 @@
|
|||
name: node-js-ci
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ${{matrix.os}}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
node: ['14', '16']
|
||||
|
||||
name: Node ${{ matrix.node }} on ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Test
|
||||
uses: actions/setup-node@v2.4.1
|
||||
with:
|
||||
node-version: ${{ matrix.node }}
|
||||
- run: npm install
|
||||
- run: npm test
|
|
@ -2,6 +2,7 @@ node_modules
|
|||
.env
|
||||
*~
|
||||
.vscode
|
||||
.idea
|
||||
|
||||
# Parcel build dirs
|
||||
.cache
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
{
|
||||
"scripts": {
|
||||
"beforeStart": "npm run test",
|
||||
"beforeBump": "npm run build",
|
||||
"changelogCommand": "git log --pretty=format:'* %s (%h)' [REV_RANGE]"
|
||||
"hooks": {
|
||||
"before:init": ["npm run test"],
|
||||
"before:bump": ["npm run build"]
|
||||
},
|
||||
"git": {
|
||||
"pushRepo": "git@github.com:filerjs/filer.git",
|
||||
"tagName": "v%s"
|
||||
"tagName": "v${version}"
|
||||
},
|
||||
"npm": {
|
||||
"publish": true
|
||||
},
|
||||
"github": {
|
||||
"release": true,
|
||||
"releaseName": "Filer.js %s Released"
|
||||
"pushRepo": "git@github.com:filerjs/filer.git",
|
||||
"release": true
|
||||
}
|
||||
}
|
||||
|
|
2
AUTHORS
2
AUTHORS
|
@ -5,3 +5,5 @@ Barry Tulchinsky <barry.tulchinsky@gmail.com> (@btulchinsky)
|
|||
Kieran Sedgwick <kieran.sedgwick@gmail.com> (@sedge)
|
||||
Yoav Gurevich <ygurevich@ymail.com>
|
||||
Gideon Thomas <r.gideonthomas@gmail.com>
|
||||
Abdirahman Guled <aguled2@myseneca.ca>
|
||||
Ben Heidemann <ben@heidemann.co.uk>
|
80
README.md
80
README.md
|
@ -54,6 +54,78 @@ requirejs(['filer'], function(Filer) {...}
|
|||
var Filer = window.Filer;
|
||||
```
|
||||
|
||||
### Webpack Plugin
|
||||
|
||||
Filer can be used as a drop-in replacement for the node.js [fs](http://nodejs.org/api/fs.html) and
|
||||
[path](http://nodejs.org/api/path.html) modules. For convenience, filer provides a webpack plugin which
|
||||
will shim the desired node.js functionality. This plugin can be used by inserting the following into
|
||||
your webpack config:
|
||||
|
||||
```javascript
|
||||
// webpack.config.js
|
||||
var { FilerWebpackPlugin } = require('filer/webpack');
|
||||
|
||||
module.exports = {
|
||||
plugins: [
|
||||
new FilerWebpackPlugin(),
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
**NOTE**
|
||||
|
||||
Previously it was recommended to access the `FilerWebpackPlugin` class by importing the main filer module. This was depracated due [this issue](https://github.com/filerjs/filer/issues/790). For anyone using ***filer version 1.4.0 or earlier***, please import the plugin class like this:
|
||||
|
||||
```javascript
|
||||
var FilerWebpackPlugin = require('filer/src/webpack-plugin');
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
You can then import the node.js [fs](http://nodejs.org/api/fs.html) and [path](http://nodejs.org/api/path.html)
|
||||
modules as normal and `FilerWebpackPlugin` will ensure that webpack will resolve references to these modules to
|
||||
the appropriate filer shims. You will then be able to use these modules as normal (with the exception of the
|
||||
synchronous fs methods e.g. `mkdirSync()`).
|
||||
|
||||
```javascript
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
```
|
||||
|
||||
The filer webpack plugin will, by default, shim the [fs](http://nodejs.org/api/fs.html) and
|
||||
[path](http://nodejs.org/api/path.html) modules. However, it's behaviour can be customised by passing an
|
||||
options object.
|
||||
|
||||
```javascript
|
||||
// webpack.config.js
|
||||
module.exports = {
|
||||
plugins: [
|
||||
new FilerWebpackPlugin({
|
||||
// Options
|
||||
}),
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
The following options can be passed to the filer webpack plugin:
|
||||
|
||||
| Option | Type | Optional | Default | Description |
|
||||
|---------------|---------|----------|--------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| filerDir | string | yes | '\<rootDir\>/node_modules/filer' | The directory in which filer is installed. |
|
||||
| shimsDir | string | yes | '\<rootDir\>/node_modules/filer/shims' | The directory in which the shims are installed. |
|
||||
| fsProviderDir | string | yes | '\<rootDir\>/node_modules/filer/shims/providers' | The directory in which the shims are located. This option is required when using a custom provider. |
|
||||
| shimFs | boolean | yes | true | Should the fs module be shimmed. |
|
||||
| shimPath | boolean | yes | true | Should the path module be shimmed. |
|
||||
| fsProvider | string | yes | 'default' | The file system provider to use. Should be one of 'default', 'indexeddb', 'memory', 'custom'. The 'default' option is equivalent to 'indexeddb'. |
|
||||
|
||||
NOTE: '\<rootDir\>' will be resolved to the current working directory.
|
||||
|
||||
Though filer also exposes the Buffer object, it is left up to the user to shim this as appropriate. This is because filer offers
|
||||
no custom implementation. Currently, filer uses the [node-libs-browser](https://github.com/webpack/node-libs-browser) Buffer implementation
|
||||
internally, though any faithful implementation of the [node.js Buffer object](http://nodejs.org/api/buffer.html) should play nicely
|
||||
with filer.
|
||||
|
||||
### Getting Started
|
||||
|
||||
Filer is as close to the node.js [fs module](http://nodejs.org/api/fs.html) as possible,
|
||||
|
@ -788,7 +860,7 @@ fs.mkdtemp("/myDir/tmp", function (error, path) {
|
|||
});
|
||||
```
|
||||
|
||||
#### fs.readdir(path, callback)<a name="readdir"></a>
|
||||
#### fs.readdir(path, [options], callback)<a name="readdir"></a>
|
||||
|
||||
Reads the contents of a directory. Asynchronous [readdir(3)](http://pubs.opengroup.org/onlinepubs/009695399/functions/readdir.html).
|
||||
Callback gets `(error, files)`, where `files` is an array containing the names of each directory entry (i.e., file, directory, link) in the directory, excluding `.` and `..`.
|
||||
|
@ -809,6 +881,12 @@ fs.readdir('/docs', function(err, files) {
|
|||
});
|
||||
```
|
||||
|
||||
Optionally accepts an options parameter, which can be either an encoding (e.g. "utf8") or an object with optional properties `encoding` and `withFileTypes`.
|
||||
|
||||
The `encoding` property is a `string` which will determine the character encoding to use for the names of each directory entry. The `withFileTypes` property is a `boolean` which defaults to `false`. If `true`, this method will return an array of [fs.Dirent](https://nodejs.org/api/fs.html#fs_class_fs_dirent) objects.
|
||||
|
||||
The `name` property on the [fs.Dirent](https://nodejs.org/api/fs.html#fs_class_fs_dirent) objects will be encoded using the specified character encoding.
|
||||
|
||||
#### fs.close(fd, callback)<a name="close"></a>
|
||||
|
||||
Closes a file descriptor. Asynchronous [close(2)](http://pubs.opengroup.org/onlinepubs/009695399/functions/close.html).
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -2,10 +2,14 @@ module.exports = function(config) {
|
|||
config.set({
|
||||
singleRun: true,
|
||||
basePath: '',
|
||||
files: ['tests/dist/index.js'],
|
||||
files: [
|
||||
'node_modules/regenerator-runtime/runtime.js',
|
||||
'tests/dist/index.js'
|
||||
],
|
||||
frameworks: ['mocha', 'chai'],
|
||||
reporters: ['mocha', 'summary'],
|
||||
client: {
|
||||
captureConsole: true,
|
||||
mocha: {
|
||||
ui: 'bdd',
|
||||
timeout: 5000,
|
||||
|
|
File diff suppressed because it is too large
Load Diff
46
package.json
46
package.json
|
@ -10,7 +10,7 @@
|
|||
"indexeddb",
|
||||
"idb"
|
||||
],
|
||||
"version": "1.1.2",
|
||||
"version": "1.4.1",
|
||||
"author": "Alan K <ack@modeswitch.org> (http://blog.modeswitch.org)",
|
||||
"homepage": "http://filerjs.github.io/filer",
|
||||
"bugs": "https://github.com/filerjs/filer/issues",
|
||||
|
@ -45,37 +45,41 @@
|
|||
"url": "https://github.com/filerjs/filer.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"es6-promisify": "^6.0.1",
|
||||
"minimatch": "^3.0.4"
|
||||
"es6-promisify": "^7.0.0",
|
||||
"minimatch": "^3.0.4",
|
||||
"schema-utils": "^3.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "^4.2.0",
|
||||
"chai-datetime": "^1.5.0",
|
||||
"eslint": "^5.10.0",
|
||||
"fake-indexeddb": "^2.0.4",
|
||||
"karma": "^3.1.4",
|
||||
"regenerator-runtime": "^0.13.9",
|
||||
"chai": "^4.3.4",
|
||||
"chai-datetime": "^1.8.0",
|
||||
"eslint": "^7.32.0",
|
||||
"fake-indexeddb": "^3.1.7",
|
||||
"karma": "^6.3.8",
|
||||
"karma-chai": "^0.1.0",
|
||||
"karma-chrome-launcher": "^2.2.0",
|
||||
"karma-firefox-launcher": "^1.1.0",
|
||||
"karma-mocha": "^1.3.0",
|
||||
"karma-chrome-launcher": "^3.1.0",
|
||||
"karma-firefox-launcher": "^2.1.2",
|
||||
"karma-mocha": "^2.0.1",
|
||||
"karma-mocha-reporter": "^2.2.5",
|
||||
"karma-summary-reporter": "^1.5.2",
|
||||
"meow": "^5.0.0",
|
||||
"mocha": "^5.2.0",
|
||||
"nyc": "^13.1.0",
|
||||
"parcel-bundler": "^1.11.0",
|
||||
"pretty-bytes": "^5.1.0",
|
||||
"release-it": "^9.3.0",
|
||||
"karma-summary-reporter": "^3.0.0",
|
||||
"meow": "^10.0.1",
|
||||
"mocha": "^9.1.3",
|
||||
"nyc": "^15.1.0",
|
||||
"parcel-bundler": "^1.12.5",
|
||||
"pretty-bytes": "^5.6.0",
|
||||
"release-it": "^14.11.6",
|
||||
"run.env": "^1.1.0",
|
||||
"unused-filename": "^1.0.0",
|
||||
"walk": "^2.3.14"
|
||||
"unused-filename": "^3.0.1",
|
||||
"walk": "^2.3.15"
|
||||
},
|
||||
"main": "./src/index.js",
|
||||
"browser": "./dist/filer.min.js",
|
||||
"files": [
|
||||
"src",
|
||||
"lib",
|
||||
"dist"
|
||||
"dist",
|
||||
"shims",
|
||||
"webpack"
|
||||
],
|
||||
"nyc": {
|
||||
"exclude": [
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
const { FileSystem } = require('../src/index');
|
||||
|
||||
let Provider;
|
||||
try {
|
||||
Provider = require('fsProvider');
|
||||
}
|
||||
catch (err) {
|
||||
Provider = require('./providers/default');
|
||||
}
|
||||
|
||||
const provider = new Provider();
|
||||
|
||||
let onFsReady;
|
||||
let onFsError;
|
||||
|
||||
let fsReady = new Promise((resolve, reject) => {
|
||||
onFsReady = resolve;
|
||||
onFsError = reject;
|
||||
});
|
||||
|
||||
var fsInstance = new FileSystem({ provider }, (err) => {
|
||||
if (err) {
|
||||
onFsError(err);
|
||||
} else {
|
||||
onFsReady(true);
|
||||
}
|
||||
});
|
||||
|
||||
function proxyHasProp(target, prop) {
|
||||
return prop in target;
|
||||
}
|
||||
|
||||
const fsPromises = new Proxy(fsInstance.promises, {
|
||||
get(target, prop) {
|
||||
if (!proxyHasProp(target, prop)) {
|
||||
return;
|
||||
}
|
||||
|
||||
return async (...args) => {
|
||||
await fsReady;
|
||||
return await target[prop](...args);
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
const fs = new Proxy(fsInstance, {
|
||||
get(target, prop) {
|
||||
if (!proxyHasProp(target, prop)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (prop === 'promises') {
|
||||
return fsPromises;
|
||||
}
|
||||
|
||||
return (...args) => {
|
||||
(async () => {
|
||||
await fsReady;
|
||||
target[prop](...args);
|
||||
})();
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = fs;
|
|
@ -0,0 +1,3 @@
|
|||
const { path } = require('../src/index');
|
||||
|
||||
module.exports = path;
|
|
@ -0,0 +1,2 @@
|
|||
const { Default } = require('../../src/providers/index');
|
||||
module.exports = Default;
|
|
@ -0,0 +1,2 @@
|
|||
const IndexedDB = require('../../src/providers/indexeddb');
|
||||
module.exports = IndexedDB;
|
|
@ -0,0 +1,2 @@
|
|||
const Memory = require('../../src/providers/memory');
|
||||
module.exports = Memory;
|
|
@ -0,0 +1,12 @@
|
|||
'use strict';
|
||||
|
||||
const Stats = require('./stats.js');
|
||||
|
||||
function Dirent(path, fileNode, devName) {
|
||||
this.constructor = Dirent;
|
||||
Stats.call(this, path, fileNode, devName);
|
||||
}
|
||||
|
||||
Dirent.prototype = Stats.prototype;
|
||||
|
||||
module.exports = Dirent;
|
|
@ -4,6 +4,7 @@ var dirname = Path.dirname;
|
|||
var basename = Path.basename;
|
||||
var isAbsolutePath = Path.isAbsolute;
|
||||
var shared = require('../shared.js');
|
||||
var async = require('../../lib/async.js');
|
||||
|
||||
var Constants = require('../constants.js');
|
||||
var NODE_TYPE_FILE = Constants.NODE_TYPE_FILE;
|
||||
|
@ -35,6 +36,7 @@ var openFiles = require('../open-files.js');
|
|||
var OpenFileDescription = require('../open-file-description.js');
|
||||
var SuperNode = require('../super-node.js');
|
||||
var Node = require('../node.js');
|
||||
var Dirent = require('../dirent.js');
|
||||
var Stats = require('../stats.js');
|
||||
|
||||
/**
|
||||
|
@ -227,7 +229,7 @@ function find_node(context, path, callback) {
|
|||
if(error) {
|
||||
callback(error);
|
||||
} else {
|
||||
if(!parentDirectoryData.hasOwnProperty(name)) {
|
||||
if(!Object.prototype.hasOwnProperty.call(parentDirectoryData, name)) {
|
||||
callback(new Errors.ENOENT(null, path));
|
||||
} else {
|
||||
var nodeId = parentDirectoryData[name].id;
|
||||
|
@ -293,10 +295,10 @@ function set_extended_attribute (context, path, node, name, value, flag, callbac
|
|||
|
||||
var xattrs = node.xattrs;
|
||||
|
||||
if (flag === XATTR_CREATE && xattrs.hasOwnProperty(name)) {
|
||||
if (flag === XATTR_CREATE && Object.prototype.hasOwnProperty.call(xattrs, name)) {
|
||||
callback(new Errors.EEXIST('attribute already exists', path));
|
||||
}
|
||||
else if (flag === XATTR_REPLACE && !xattrs.hasOwnProperty(name)) {
|
||||
else if (flag === XATTR_REPLACE && !Object.prototype.hasOwnProperty.call(xattrs, name)) {
|
||||
callback(new Errors.ENOATTR(null, path));
|
||||
}
|
||||
else {
|
||||
|
@ -478,7 +480,7 @@ function access_file(context, path, mode, callback) {
|
|||
}
|
||||
|
||||
// In any other case, the file isn't accessible
|
||||
callback(new Errors.EACCES('permission denied',path)) ;
|
||||
callback(new Errors.EACCES('permission denied',path)) ;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -509,7 +511,7 @@ function remove_directory(context, path, callback) {
|
|||
callback(error);
|
||||
} else if(ROOT_DIRECTORY_NAME === name) {
|
||||
callback(new Errors.EBUSY(null, path));
|
||||
} else if(!result.hasOwnProperty(name)) {
|
||||
} else if(!Object.prototype.hasOwnProperty.call(result, name)) {
|
||||
callback(new Errors.ENOENT(null, path));
|
||||
} else {
|
||||
parentDirectoryData = result;
|
||||
|
@ -618,9 +620,9 @@ function open_file(context, path, flags, mode, callback) {
|
|||
callback(error);
|
||||
} else {
|
||||
directoryData = result;
|
||||
if(directoryData.hasOwnProperty(name)) {
|
||||
if(Object.prototype.hasOwnProperty.call(directoryData, name)) {
|
||||
if(flags.includes(O_EXCLUSIVE)) {
|
||||
callback(new Errors.ENOENT('O_CREATE and O_EXCLUSIVE are set, and the named file exists', path));
|
||||
callback(new Errors.EEXIST('O_CREATE and O_EXCLUSIVE are set, and the named file exists', path));
|
||||
} else {
|
||||
directoryEntry = directoryData[name];
|
||||
if(directoryEntry.type === NODE_TYPE_DIRECTORY && flags.includes(O_WRITE)) {
|
||||
|
@ -929,7 +931,7 @@ function lstat_file(context, path, callback) {
|
|||
callback(error);
|
||||
} else {
|
||||
directoryData = result;
|
||||
if(!directoryData.hasOwnProperty(name)) {
|
||||
if(!Object.prototype.hasOwnProperty.call(directoryData, name)) {
|
||||
callback(new Errors.ENOENT('a component of the path does not name an existing file', path));
|
||||
} else {
|
||||
context.getObject(directoryData[name].id, create_node);
|
||||
|
@ -986,7 +988,7 @@ function link_node(context, oldpath, newpath, callback) {
|
|||
callback(error);
|
||||
} else {
|
||||
newDirectoryData = result;
|
||||
if(newDirectoryData.hasOwnProperty(newname)) {
|
||||
if(Object.prototype.hasOwnProperty.call(newDirectoryData, newname)) {
|
||||
callback(new Errors.EEXIST('newpath resolves to an existing file', newname));
|
||||
} else {
|
||||
newDirectoryData[newname] = oldDirectoryData[oldname];
|
||||
|
@ -1010,7 +1012,7 @@ function link_node(context, oldpath, newpath, callback) {
|
|||
callback(error);
|
||||
} else {
|
||||
oldDirectoryData = result;
|
||||
if(!oldDirectoryData.hasOwnProperty(oldname)) {
|
||||
if(!Object.prototype.hasOwnProperty.call(oldDirectoryData, oldname)) {
|
||||
callback(new Errors.ENOENT('a component of either path prefix does not exist', oldname));
|
||||
} else if(oldDirectoryData[oldname].type === NODE_TYPE_DIRECTORY) {
|
||||
callback(new Errors.EPERM('oldpath refers to a directory'));
|
||||
|
@ -1077,7 +1079,7 @@ function unlink_node(context, path, callback) {
|
|||
context.putObject(fileNode.id, fileNode, function(error) {
|
||||
if(error) {
|
||||
callback(error);
|
||||
} else {
|
||||
} else {
|
||||
update_node_times(context, path, fileNode, { ctime: Date.now() }, update_directory_data);
|
||||
}
|
||||
});
|
||||
|
@ -1100,7 +1102,7 @@ function unlink_node(context, path, callback) {
|
|||
callback(error);
|
||||
} else {
|
||||
directoryData = result;
|
||||
if(!directoryData.hasOwnProperty(name)) {
|
||||
if(!Object.prototype.hasOwnProperty.call(directoryData, name)) {
|
||||
callback(new Errors.ENOENT('a component of the path does not name an existing file', name));
|
||||
} else {
|
||||
context.getObject(directoryData[name].id, check_if_node_is_directory);
|
||||
|
@ -1120,26 +1122,72 @@ function unlink_node(context, path, callback) {
|
|||
find_node(context, parentPath, read_directory_data);
|
||||
}
|
||||
|
||||
function read_directory(context, path, callback) {
|
||||
function read_directory(context, path, options, callback) {
|
||||
path = normalize(path);
|
||||
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
options = validate_directory_options(options);
|
||||
|
||||
var directoryNode;
|
||||
var directoryData;
|
||||
|
||||
function handle_directory_data(error, result) {
|
||||
if(error) {
|
||||
if (error) {
|
||||
callback(error);
|
||||
} else {
|
||||
directoryData = result;
|
||||
var files = Object.keys(directoryData);
|
||||
callback(null, files);
|
||||
|
||||
if (options.encoding) {
|
||||
var fileBuffers = files.map(function (file) {
|
||||
return Buffer.from(file);
|
||||
});
|
||||
|
||||
if (options.encoding === 'buffer') {
|
||||
files = fileBuffers;
|
||||
}
|
||||
else {
|
||||
files = fileBuffers.map(function (fileBuffer) {
|
||||
return fileBuffer.toString(options.encoding);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (options.withFileTypes) {
|
||||
var dirEnts = [];
|
||||
|
||||
// eslint-disable-next-line no-inner-declarations
|
||||
function to_dir_entry(file, callback) {
|
||||
const filename = Buffer.from(file, options.encoding).toString();
|
||||
const filepath = Path.join(path, filename);
|
||||
get_dir_entry(context, filepath, function(error, dirEnt) {
|
||||
if (error) {
|
||||
callback(error);
|
||||
}
|
||||
dirEnt.name = file;
|
||||
dirEnts.push(dirEnt);
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
async.eachSeries(files, to_dir_entry, function (error) {
|
||||
callback(error, dirEnts);
|
||||
});
|
||||
}
|
||||
|
||||
else {
|
||||
callback(null, files);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function read_directory_data(error, result) {
|
||||
if(error) {
|
||||
if (error) {
|
||||
callback(error);
|
||||
} else if(result.type !== NODE_TYPE_DIRECTORY) {
|
||||
} else if (result.type !== NODE_TYPE_DIRECTORY) {
|
||||
callback(new Errors.ENOTDIR(null, path));
|
||||
} else {
|
||||
directoryNode = result;
|
||||
|
@ -1150,6 +1198,30 @@ function read_directory(context, path, callback) {
|
|||
find_node(context, path, read_directory_data);
|
||||
}
|
||||
|
||||
function get_dir_entry(context, path, callback) {
|
||||
function check_result(error, result) {
|
||||
if(error) {
|
||||
callback(error);
|
||||
} else {
|
||||
var stats = new Dirent(path, result, context.name);
|
||||
callback(null, stats);
|
||||
}
|
||||
}
|
||||
|
||||
lstat_file(context, path, check_result);
|
||||
}
|
||||
|
||||
function validate_directory_options(options, enc) {
|
||||
if (!options) {
|
||||
options = { encoding: enc };
|
||||
} else if (typeof options === 'function') {
|
||||
options = { encoding: enc };
|
||||
} else if (typeof options === 'string') {
|
||||
options = { encoding: options };
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
function make_symbolic_link(context, srcpath, dstpath, callback) {
|
||||
dstpath = normalize(dstpath);
|
||||
var name = basename(dstpath);
|
||||
|
@ -1179,7 +1251,7 @@ function make_symbolic_link(context, srcpath, dstpath, callback) {
|
|||
callback(error);
|
||||
} else {
|
||||
directoryData = result;
|
||||
if(directoryData.hasOwnProperty(name)) {
|
||||
if(Object.prototype.hasOwnProperty.call(directoryData, name)) {
|
||||
callback(new Errors.EEXIST(null, name));
|
||||
} else {
|
||||
write_file_node();
|
||||
|
@ -1203,12 +1275,12 @@ function make_symbolic_link(context, srcpath, dstpath, callback) {
|
|||
// but store both versions, since we'll use the relative one in readlink().
|
||||
if(!isAbsolutePath(srcpath)) {
|
||||
fileNode.symlink_relpath = srcpath;
|
||||
srcpath = Path.resolve(parentPath, srcpath);
|
||||
srcpath = Path.resolve(parentPath, srcpath);
|
||||
}
|
||||
|
||||
fileNode.size = srcpath.length;
|
||||
fileNode.data = srcpath;
|
||||
|
||||
|
||||
context.putObject(fileNode.id, fileNode, update_directory_data);
|
||||
});
|
||||
}
|
||||
|
@ -1256,7 +1328,7 @@ function read_link(context, path, callback) {
|
|||
callback(error);
|
||||
} else {
|
||||
directoryData = result;
|
||||
if(!directoryData.hasOwnProperty(name)) {
|
||||
if(!Object.prototype.hasOwnProperty.call(directoryData, name)) {
|
||||
callback(new Errors.ENOENT('a component of the path does not name an existing file', name));
|
||||
} else {
|
||||
context.getObject(directoryData[name].id, check_if_symbolic);
|
||||
|
@ -1495,7 +1567,7 @@ function getxattr_file (context, path, name, callback) {
|
|||
|
||||
var xattrs = node.xattrs;
|
||||
|
||||
if (!xattrs.hasOwnProperty(name)) {
|
||||
if (!Object.prototype.hasOwnProperty.call(xattrs, name)) {
|
||||
callback(new Errors.ENOATTR(null, path));
|
||||
}
|
||||
else {
|
||||
|
@ -1523,7 +1595,7 @@ function fgetxattr_file (context, ofd, name, callback) {
|
|||
|
||||
var xattrs = node.xattrs;
|
||||
|
||||
if (!xattrs.hasOwnProperty(name)) {
|
||||
if (!Object.prototype.hasOwnProperty.call(xattrs, name)) {
|
||||
callback(new Errors.ENOATTR());
|
||||
}
|
||||
else {
|
||||
|
@ -1560,7 +1632,7 @@ function removexattr_file (context, path, name, callback) {
|
|||
|
||||
var xattrs = node.xattrs;
|
||||
|
||||
if (!xattrs.hasOwnProperty(name)) {
|
||||
if (!Object.prototype.hasOwnProperty.call(xattrs, name)) {
|
||||
callback(new Errors.ENOATTR(null, path));
|
||||
}
|
||||
else {
|
||||
|
@ -1597,7 +1669,7 @@ function fremovexattr_file (context, ofd, name, callback) {
|
|||
|
||||
var xattrs = node.xattrs;
|
||||
|
||||
if (!xattrs.hasOwnProperty(name)) {
|
||||
if (!Object.prototype.hasOwnProperty.call(xattrs, name)) {
|
||||
callback(new Errors.ENOATTR());
|
||||
}
|
||||
else {
|
||||
|
@ -1618,7 +1690,7 @@ function fremovexattr_file (context, ofd, name, callback) {
|
|||
}
|
||||
|
||||
function validate_flags(flags) {
|
||||
return O_FLAGS.hasOwnProperty(flags) ? O_FLAGS[flags] : null;
|
||||
return Object.prototype.hasOwnProperty.call(O_FLAGS, flags) ? O_FLAGS[flags] : null;
|
||||
}
|
||||
|
||||
function validate_file_options(options, enc, fileMode){
|
||||
|
@ -1686,7 +1758,7 @@ function mkdir(context, path, mode, callback) {
|
|||
mode = validateAndMaskMode(mode, FULL_READ_WRITE_EXEC_PERMISSIONS, callback);
|
||||
if(!mode) return;
|
||||
}
|
||||
|
||||
|
||||
make_directory(context, path, callback);
|
||||
}
|
||||
|
||||
|
@ -1704,14 +1776,14 @@ function mkdtemp(context, prefix, options, callback) {
|
|||
callback = arguments[arguments.length - 1];
|
||||
if(!prefix) {
|
||||
return callback(new Error('filename prefix is required'));
|
||||
}
|
||||
}
|
||||
|
||||
let random = shared.randomChars(6);
|
||||
var path = prefix + '-' + random;
|
||||
var path = prefix + '-' + random;
|
||||
|
||||
make_directory(context, path, function(error) {
|
||||
callback(error, path);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function rmdir(context, path, callback) {
|
||||
|
@ -1869,12 +1941,17 @@ function writeFile(context, path, data, options, callback) {
|
|||
return callback(new Errors.EINVAL('flags is not valid', path));
|
||||
}
|
||||
|
||||
data = data || '';
|
||||
if(typeof data === 'number') {
|
||||
data = '' + data;
|
||||
}
|
||||
if(typeof data === 'string' && options.encoding === 'utf8') {
|
||||
data = Buffer.from(data);
|
||||
if(!Buffer.isBuffer(data)) {
|
||||
if(typeof data === 'number') {
|
||||
data = '' + data;
|
||||
}
|
||||
data = data || '';
|
||||
if(typeof data !== 'string') {
|
||||
data = Buffer.from(data.toString());
|
||||
}
|
||||
else {
|
||||
data = Buffer.from(data || '', options.encoding || 'utf8');
|
||||
}
|
||||
}
|
||||
|
||||
open_file(context, path, flags, function(err, fileNode) {
|
||||
|
@ -2158,8 +2235,8 @@ function lseek(context, fd, offset, whence, callback) {
|
|||
}
|
||||
}
|
||||
|
||||
function readdir(context, path, callback) {
|
||||
read_directory(context, path, callback);
|
||||
function readdir(context, path, options, callback) {
|
||||
read_directory(context, path, options, callback);
|
||||
}
|
||||
|
||||
function toUnixTimestamp(time) {
|
||||
|
@ -2249,7 +2326,7 @@ function rename(context, oldpath, newpath, callback) {
|
|||
newpath = normalize(newpath);
|
||||
|
||||
var oldParentPath = Path.dirname(oldpath);
|
||||
var newParentPath = Path.dirname(oldpath);
|
||||
var newParentPath = Path.dirname(newpath);
|
||||
var oldName = Path.basename(oldpath);
|
||||
var newName = Path.basename(newpath);
|
||||
var oldParentDirectory, oldParentData;
|
||||
|
@ -2300,7 +2377,7 @@ function rename(context, oldpath, newpath, callback) {
|
|||
callback(error);
|
||||
} else {
|
||||
newParentData = result;
|
||||
if(newParentData.hasOwnProperty(newName)) {
|
||||
if(Object.prototype.hasOwnProperty.call(newParentData, newName)) {
|
||||
remove_directory(context, newpath, update_new_parent_directory_data);
|
||||
} else {
|
||||
update_new_parent_directory_data();
|
||||
|
|
12
src/index.js
12
src/index.js
|
@ -8,7 +8,17 @@ module.exports = Filer = {
|
|||
Path: require('./path.js'),
|
||||
path: require('./path.js'),
|
||||
Errors: require('./errors.js'),
|
||||
Shell: require('./shell/shell.js')
|
||||
Shell: require('./shell/shell.js'),
|
||||
/**
|
||||
* @deprecated Importing filer from your webpack config is not recommended.
|
||||
*
|
||||
* The filer `FilerWebpackPlugin` class is exposed directly.
|
||||
*
|
||||
* ```
|
||||
* const { FilerWebpackPlugin } = require('filer/webpack');
|
||||
* ```
|
||||
*/
|
||||
FilerWebpackPlugin: require('./webpack-plugin'),
|
||||
};
|
||||
|
||||
// Add a getter for the `fs` instance, which returns
|
||||
|
|
|
@ -10,7 +10,7 @@ process.cwd = () => '/';
|
|||
* a few things we need for the browser environment.
|
||||
*/
|
||||
const nodePath = require('path');
|
||||
const filerPath = Object.create(nodePath);
|
||||
const filerPath = Object.assign({}, nodePath);
|
||||
|
||||
/**
|
||||
* Patch path.basename() to return / vs. ''
|
||||
|
|
|
@ -9,7 +9,7 @@ var asyncCallback = require('../../lib/async.js').setImmediate;
|
|||
var createDB = (function() {
|
||||
var pool = {};
|
||||
return function getOrCreate(name) {
|
||||
if(!pool.hasOwnProperty(name)) {
|
||||
if(!Object.prototype.hasOwnProperty.call(pool, name)) {
|
||||
pool[name] = {};
|
||||
}
|
||||
return pool[name];
|
||||
|
|
|
@ -387,7 +387,8 @@ Shell.prototype.mkdirp = function(path, callback) {
|
|||
callback(new Errors.EINVAL('Missing path argument'));
|
||||
return;
|
||||
}
|
||||
else if (path === '/') {
|
||||
path = Path.resolve(sh.pwd(), path);
|
||||
if (path === '/') {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
var path = require('path');
|
||||
var utils = require('./utils');
|
||||
|
||||
const PLUGIN_NAME = 'filer-webpack-plugin';
|
||||
|
||||
const OPTIONS_SCHEMA = require('./schema');
|
||||
const OPTIONS_PROCESSORS = require('./processors');
|
||||
|
||||
module.exports = class FilerWebpackPlugin {
|
||||
|
||||
constructor(options = {}) {
|
||||
utils.validateOptions(options, OPTIONS_SCHEMA);
|
||||
this.options = utils.processOptions(options, OPTIONS_PROCESSORS);
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
compiler.hooks.normalModuleFactory.tap(
|
||||
PLUGIN_NAME,
|
||||
(factory) => {
|
||||
factory.hooks.resolve.tap(
|
||||
PLUGIN_NAME,
|
||||
(resolveData) => {
|
||||
// Resolve fsProvider if required
|
||||
if (
|
||||
resolveData.request === 'fsProvider'
|
||||
&& resolveData.context === this.options.shimsDir
|
||||
) {
|
||||
return this.resolveFsProvider(resolveData);
|
||||
}
|
||||
|
||||
// Ignore filer files (these should resolve modules normally)
|
||||
if (resolveData.context.startsWith(this.options.filerDir)) return;
|
||||
|
||||
// Apply fs, path and buffer shims if required
|
||||
switch (resolveData.request) {
|
||||
case 'fs':
|
||||
if (!this.options.shimFs) return;
|
||||
return this.applyFsShim(resolveData);
|
||||
case 'path':
|
||||
if (!this.options.shimPath) return;
|
||||
return this.applyPathShim(resolveData);
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
resolveFsProvider(resolveData) {
|
||||
switch (this.options.fsProvider) {
|
||||
case 'default':
|
||||
resolveData.request = path.join(this.options.fsProviderDir, 'default.js');
|
||||
break;
|
||||
case 'indexeddb':
|
||||
resolveData.request = path.join(this.options.fsProviderDir, 'indexeddb.js');
|
||||
break;
|
||||
case 'memory':
|
||||
resolveData.request = path.join(this.options.fsProviderDir, 'memory.js');
|
||||
break;
|
||||
case 'custom':
|
||||
resolveData.request = path.join(this.options.fsProviderDir, 'custom.js');
|
||||
break;
|
||||
default:
|
||||
throw new Error([
|
||||
'Invalid option for fsProvider.',
|
||||
'fsProvider must be one of \'default\', \'indexeddb\', \'memory\' or \'custom\'.',
|
||||
'If using a custom fsProvider, you must also provide the fsProviderDir option.'
|
||||
].join(' '));
|
||||
}
|
||||
}
|
||||
|
||||
applyFsShim(resolveData) {
|
||||
resolveData.request = path.join(this.options.shimsDir, 'fs.js');
|
||||
}
|
||||
|
||||
applyPathShim(resolveData) {
|
||||
resolveData.request = path.join(this.options.shimsDir, 'path.js');
|
||||
}
|
||||
};
|
|
@ -0,0 +1,34 @@
|
|||
var path = require('path');
|
||||
|
||||
const ROOT_DIR_TAG = '<rootDir>';
|
||||
const CWD = process.cwd();
|
||||
|
||||
module.exports = {
|
||||
filerDir: {
|
||||
process: function(value) {
|
||||
if (!value) {
|
||||
return path.join(CWD, 'node_modules', 'filer');
|
||||
}
|
||||
return path.resolve(value.replace(ROOT_DIR_TAG, CWD));
|
||||
},
|
||||
},
|
||||
shimsDir: {
|
||||
process: function(value) {
|
||||
if (!value) {
|
||||
return path.join(CWD, 'node_modules', 'filer', 'shims');
|
||||
}
|
||||
return path.resolve(value.replace(ROOT_DIR_TAG, CWD));
|
||||
}
|
||||
},
|
||||
fsProviderDir: {
|
||||
process: function(value) {
|
||||
if (!value) {
|
||||
return path.join(CWD, 'node_modules', 'filer', 'shims', 'providers');
|
||||
}
|
||||
return path.resolve(value.replace(ROOT_DIR_TAG, CWD));
|
||||
},
|
||||
},
|
||||
shimFs: { default: true },
|
||||
shimPath: { default: true},
|
||||
fsProvider: { default: 'default'},
|
||||
};
|
|
@ -0,0 +1,23 @@
|
|||
module.exports = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
filerDir: {
|
||||
type: 'string',
|
||||
},
|
||||
shimsDir: {
|
||||
type: 'string',
|
||||
},
|
||||
shimFs: {
|
||||
type: 'boolean',
|
||||
},
|
||||
shimPath: {
|
||||
type: 'boolean',
|
||||
},
|
||||
fsProvider: {
|
||||
type: 'string',
|
||||
},
|
||||
fsProviderDir: {
|
||||
type: 'string',
|
||||
},
|
||||
}
|
||||
};
|
|
@ -0,0 +1,26 @@
|
|||
var { validate } = require('schema-utils');
|
||||
|
||||
function validateOptions(options, schema) {
|
||||
validate(schema, options);
|
||||
}
|
||||
|
||||
function processOptions(options, processors) {
|
||||
const processedOptions = {};
|
||||
|
||||
for (const [property, processor] of Object.entries(processors)) {
|
||||
processedOptions[property] = options[property];
|
||||
if (processedOptions[property] === undefined) {
|
||||
processedOptions[property] = processor.default;
|
||||
}
|
||||
if (processor.process) {
|
||||
processedOptions[property] = processor.process(processedOptions[property]);
|
||||
}
|
||||
}
|
||||
|
||||
return processedOptions;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
validateOptions,
|
||||
processOptions,
|
||||
};
|
|
@ -0,0 +1,12 @@
|
|||
'use strict';
|
||||
const util = require('../lib/test-utils.js');
|
||||
|
||||
describe('unexpected failures when calling fs functions (e.g. writeFile) with empty options object, issue 773', function() {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should call fs.writeFile with an empty options object', function(done) {
|
||||
const fs = util.fs();
|
||||
fs.writeFile('/a', 'trololol', {}, done);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,115 @@
|
|||
'use strict';
|
||||
var util = require('../lib/test-utils.js');
|
||||
var expect = require('chai').expect;
|
||||
|
||||
describe('fs.readdir fails when passing options, issue775', function () {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
function setup(fs, dir, cb) {
|
||||
fs.mkdir(dir, undefined, (err) => {
|
||||
if (err) {
|
||||
cb(err);
|
||||
}
|
||||
else {
|
||||
fs.writeFile(dir + '/file', '', (err) => {
|
||||
if (err) {
|
||||
cb(err);
|
||||
}
|
||||
else {
|
||||
fs.mkdir(dir + '/folder', (err) => {
|
||||
if (err) {
|
||||
cb(err);
|
||||
}
|
||||
else {
|
||||
fs.symlink(dir + '/file', dir + '/symlink', (err) => {
|
||||
if (err) {
|
||||
cb(err);
|
||||
}
|
||||
else {
|
||||
cb();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
it('should create a directory, add a file, folder and symbolic link then call fs.readdir with buffer encoding', function (done) {
|
||||
var fs = util.fs();
|
||||
setup(fs, '/test_dir', (err) => {
|
||||
if (err) {
|
||||
done(err);
|
||||
}
|
||||
fs.readdir('/test_dir', 'buffer', (err, data) => {
|
||||
if (err) {
|
||||
done(err);
|
||||
}
|
||||
else {
|
||||
expect(data).to.have.length(3);
|
||||
|
||||
expect(data[0].toString()).to.equal('file');
|
||||
expect(data[1].toString()).to.equal('folder');
|
||||
expect(data[2].toString()).to.equal('symlink');
|
||||
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a directory, add a file, folder and symbolic link then call fs.readdir with withFileTypes and encoding options', function (done) {
|
||||
var fs = util.fs();
|
||||
setup(fs, '/test_dir', (err) => {
|
||||
if (err) {
|
||||
done(err);
|
||||
}
|
||||
fs.readdir('/test_dir', { encoding: 'base64', withFileTypes: true }, (err, data) => {
|
||||
if (err) {
|
||||
done(err);
|
||||
}
|
||||
else {
|
||||
expect(data).to.have.length(3);
|
||||
|
||||
expect(Buffer.from(data[0].name, 'base64').toString()).to.equal('file');
|
||||
expect(Buffer.from(data[1].name, 'base64').toString()).to.equal('folder');
|
||||
expect(Buffer.from(data[2].name, 'base64').toString()).to.equal('symlink');
|
||||
|
||||
expect(data[0].isFile()).to.be.true;
|
||||
expect(data[1].isDirectory()).to.be.true;
|
||||
expect(data[2].isSymbolicLink()).to.be.true;
|
||||
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a directory then call fs.readdir without options', function (done) {
|
||||
var fs = util.fs();
|
||||
setup(fs, '/test_dir', (err) => {
|
||||
if (err) {
|
||||
done(err);
|
||||
}
|
||||
else {
|
||||
fs.readdir('/test_dir', (err, data) => {
|
||||
if (err) {
|
||||
done(err);
|
||||
}
|
||||
else {
|
||||
expect(data).to.have.length(3);
|
||||
|
||||
expect(data[0]).to.equal('file');
|
||||
expect(data[1]).to.equal('folder');
|
||||
expect(data[2]).to.equal('symlink');
|
||||
|
||||
done();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,12 @@
|
|||
'use strict';
|
||||
const util = require('../lib/test-utils.js');
|
||||
|
||||
describe('fs.mkdir does not recursively create parent directories when called with { recursive: true }, issue776', function() {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it.skip('should not throw when calling fs.mkdir with recursive flag set', function(done) {
|
||||
const fs = util.fs();
|
||||
fs.mkdir('/test_dir/a/b', { recursive: true }, done);
|
||||
});
|
||||
});
|
|
@ -12,7 +12,7 @@
|
|||
<script src="../node_modules/mocha/mocha.js"></script>
|
||||
|
||||
<script>
|
||||
mocha.setup('bdd').timeout(5000).slow(250);
|
||||
mocha.setup('bdd').timeout(10000).slow(250);
|
||||
|
||||
window.onload = function() {
|
||||
mocha.checkLeaks();
|
||||
|
|
|
@ -3,6 +3,13 @@
|
|||
* get them running by default.
|
||||
*/
|
||||
|
||||
// Shims
|
||||
require('./spec/shims/fs.spec');
|
||||
require('./spec/shims/path.spec');
|
||||
|
||||
// Webpack Plugin
|
||||
require('./spec/webpack-plugin/webpack-plugin.spec');
|
||||
|
||||
// Filer
|
||||
require('./spec/filer.spec');
|
||||
require('./spec/filer.buffer.spec.js');
|
||||
|
@ -36,7 +43,6 @@ require('./spec/fs.truncate.spec');
|
|||
require('./spec/fs.ftruncate.spec');
|
||||
require('./spec/fs.utimes.spec');
|
||||
require('./spec/fs.xattr.spec');
|
||||
require('./spec/fs.stats.spec');
|
||||
require('./spec/path-resolution.spec');
|
||||
require('./spec/trailing-slashes.spec');
|
||||
require('./spec/times.spec');
|
||||
|
@ -85,6 +91,9 @@ require('./bugs/issue267.js');
|
|||
require('./bugs/issue270.js');
|
||||
require('./bugs/rename-dir-trailing-slash.js');
|
||||
require('./bugs/issue357.js');
|
||||
require('./bugs/issue773.js');
|
||||
require('./bugs/issue775.js');
|
||||
require('./bugs/issue776.js');
|
||||
|
||||
// Sample code from README
|
||||
require('./spec/readme.example.spec');
|
||||
|
|
|
@ -52,11 +52,13 @@ function shimIndexedDB(fn) {
|
|||
global.indexedDB = require('fake-indexeddb');
|
||||
}
|
||||
|
||||
fn();
|
||||
var result = fn();
|
||||
|
||||
if(addShim) {
|
||||
delete global.indexedDB;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function setup(callback) {
|
||||
|
@ -157,6 +159,24 @@ const parseBJSON = json =>
|
|||
value
|
||||
);
|
||||
|
||||
function createMockFn(implementation = undefined) {
|
||||
const calls = [];
|
||||
const mockFn = function(...args) {
|
||||
calls.push({
|
||||
args,
|
||||
});
|
||||
if (typeof implementation === 'function') {
|
||||
return implementation(...args);
|
||||
}
|
||||
};
|
||||
Object.defineProperty(mockFn, 'calls', {
|
||||
get() {
|
||||
return calls;
|
||||
}
|
||||
});
|
||||
return mockFn;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
uniqueName: uniqueName,
|
||||
setup: setup,
|
||||
|
@ -170,5 +190,6 @@ module.exports = {
|
|||
cleanup: cleanup,
|
||||
typedArrayEqual: typedArrayEqual,
|
||||
parseBJSON,
|
||||
shimIndexedDB
|
||||
shimIndexedDB,
|
||||
createMockFn
|
||||
};
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
var util = require('../lib/test-utils.js');
|
||||
var expect = require('chai').expect;
|
||||
'use strict';
|
||||
const util = require('../lib/test-utils.js');
|
||||
const expect = require('chai').expect;
|
||||
|
||||
describe('fs.exists', function() {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
expect(typeof fs.exists).to.equal('function');
|
||||
});
|
||||
|
||||
it('should return false if path does not exist', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
fs.exists('/tmp', function(result) {
|
||||
expect(result).to.be.false;
|
||||
|
@ -20,7 +21,7 @@ describe('fs.exists', function() {
|
|||
});
|
||||
|
||||
it('should return true if path exists', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
fs.open('/myfile', 'w', function(err, fd) {
|
||||
if(err) throw err;
|
||||
|
@ -37,7 +38,7 @@ describe('fs.exists', function() {
|
|||
});
|
||||
|
||||
it('should follow symbolic links and return true for the resulting path', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
fs.open('/myfile', 'w', function(error, fd) {
|
||||
if(error) throw error;
|
||||
|
@ -58,7 +59,7 @@ describe('fs.exists', function() {
|
|||
});
|
||||
|
||||
it('should follow symbolic links and return false if for the resulting path does not exist', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
fs.open('/myfile', 'w', function(error, fd) {
|
||||
if(error) throw error;
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
var util = require('../lib/test-utils.js');
|
||||
var expect = require('chai').expect;
|
||||
'use strict';
|
||||
const util = require('../lib/test-utils.js');
|
||||
const expect = require('chai').expect;
|
||||
|
||||
describe('fs.lstat', function() {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
expect(typeof fs.lstat).to.equal('function');
|
||||
});
|
||||
|
||||
it('should return an error if path does not exist', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
const fs = util.fs();
|
||||
|
||||
fs.lstat('/tmp', function(error, result) {
|
||||
expect(error).to.exist;
|
||||
expect(error.code).to.equal('ENOENT');
|
||||
|
@ -22,8 +23,8 @@ describe('fs.lstat', function() {
|
|||
});
|
||||
|
||||
it('should return a stat object if path is not a symbolic link', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
const fs = util.fs();
|
||||
|
||||
fs.lstat('/', function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.exist;
|
||||
|
@ -33,8 +34,8 @@ describe('fs.lstat', function() {
|
|||
});
|
||||
|
||||
it('should return a stat object if path is a symbolic link', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
const fs = util.fs();
|
||||
|
||||
fs.symlink('/', '/mylink', function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
|
@ -74,7 +75,7 @@ describe('fs.promises.lstat', () => {
|
|||
afterEach(util.cleanup);
|
||||
|
||||
it('should return an error if path does not exist', () => {
|
||||
var fsPromises = util.fs().promises;
|
||||
const fsPromises = util.fs().promises;
|
||||
|
||||
return fsPromises.lstat('/tmp')
|
||||
.catch( error => {
|
||||
|
@ -84,8 +85,8 @@ describe('fs.promises.lstat', () => {
|
|||
});
|
||||
|
||||
it('should return a stat object if path is not a symbolic link', () => {
|
||||
var fsPromises = util.fs().promises;
|
||||
|
||||
const fsPromises = util.fs().promises;
|
||||
|
||||
return fsPromises.lstat('/')
|
||||
.then(result => {
|
||||
expect(result).to.exist;
|
||||
|
|
|
@ -47,6 +47,23 @@ describe('fs.open', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should return an error when flagged for write and the path exists', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
fs.mkdir('/tmp', function(error) {
|
||||
if(error) throw error;
|
||||
fs.writeFile('/tmp/file', 'data', function(error) {
|
||||
if(error) throw error;
|
||||
fs.open('/tmp/file', 'wx', function(error, result) {
|
||||
expect(error).to.exist;
|
||||
expect(error.code).to.equal('EEXIST');
|
||||
expect(result).not.to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an error when flagged for append and the path is a directory', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
var util = require('../lib/test-utils.js');
|
||||
var expect = require('chai').expect;
|
||||
'use strict';
|
||||
const util = require('../lib/test-utils.js');
|
||||
const expect = require('chai').expect;
|
||||
|
||||
describe('fs.read', function() {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
expect(fs.read).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should read data from a file', function(done) {
|
||||
var fs = util.fs();
|
||||
var wbuffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
var rbuffer = Buffer.alloc(wbuffer.length);
|
||||
const fs = util.fs();
|
||||
const wbuffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
const rbuffer = Buffer.alloc(wbuffer.length);
|
||||
|
||||
fs.open('/myfile', 'w+', function(error, fd) {
|
||||
if(error) throw error;
|
||||
|
@ -33,10 +34,10 @@ describe('fs.read', function() {
|
|||
});
|
||||
|
||||
it('should update the current file position', function(done) {
|
||||
var fs = util.fs();
|
||||
var wbuffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
var rbuffer = Buffer.alloc(wbuffer.length);
|
||||
var _result = 0;
|
||||
const fs = util.fs();
|
||||
const wbuffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
const rbuffer = Buffer.alloc(wbuffer.length);
|
||||
let _result = 0;
|
||||
|
||||
fs.open('/myfile', 'w+', function(error, fd) {
|
||||
if(error) throw error;
|
||||
|
@ -63,9 +64,9 @@ describe('fs.read', function() {
|
|||
});
|
||||
|
||||
it('should fail to read a directory', function(done) {
|
||||
var fs = util.fs();
|
||||
var buf = Buffer.alloc(20);
|
||||
var buf2 = Buffer.alloc(20);
|
||||
const fs = util.fs();
|
||||
const buf = Buffer.alloc(20);
|
||||
const buf2 = Buffer.alloc(20);
|
||||
|
||||
fs.mkdir('/mydir', function(error) {
|
||||
if(error) throw error;
|
||||
|
@ -85,10 +86,10 @@ describe('fs.read', function() {
|
|||
});
|
||||
|
||||
it('should fail to read a file that does not exist', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
var fd = 0;
|
||||
var rbuffer = Buffer.alloc(8);
|
||||
const fd = 0;
|
||||
const rbuffer = Buffer.alloc(8);
|
||||
|
||||
fs.read(fd, rbuffer, 0, rbuffer.length, 0, function(error, result) {
|
||||
expect(error).to.exist;
|
||||
|
|
|
@ -3,42 +3,57 @@
|
|||
const util = require('../lib/test-utils.js');
|
||||
const expect = require('chai').expect;
|
||||
|
||||
describe('fs.readlink', function() {
|
||||
describe('fs.readlink', function () {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
it('should be a function', function () {
|
||||
const fs = util.fs();
|
||||
expect(fs.readlink).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should return an error if part of the parent destination path does not exist', function(done) {
|
||||
it('should return an error if part of the parent destination path does not exist', function (done) {
|
||||
const fs = util.fs();
|
||||
|
||||
fs.readlink('/tmp/mydir', function(error) {
|
||||
fs.readlink('/tmp/mydir', function (error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.code).to.equal('ENOENT');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an error if the path is not a symbolic link', function(done) {
|
||||
it('should return an error if the path is not a symbolic link', function (done) {
|
||||
const fs = util.fs();
|
||||
|
||||
fs.readlink('/', function(error) {
|
||||
fs.readlink('/', function (error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.code).to.equal('ENOENT');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the contents of a symbolic link', function(done) {
|
||||
it('should return an error if the path is not a symbolic link', function (done) {
|
||||
const fs = util.fs();
|
||||
|
||||
fs.symlink('/', '/myfile', function(error) {
|
||||
if(error) throw error;
|
||||
fs.mkdir('/tmp', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
fs.readlink('/myfile', function(error, result) {
|
||||
fs.readlink('/tmp', function (error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.code).to.equal('EINVAL');
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the contents of a symbolic link', function (done) {
|
||||
const fs = util.fs();
|
||||
|
||||
fs.symlink('/', '/myfile', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
fs.readlink('/myfile', function (error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.equal('/');
|
||||
done();
|
||||
|
@ -46,24 +61,24 @@ describe('fs.readlink', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should allow relative paths, but resolve to the dstpath', function(done) {
|
||||
it('should allow relative paths, but resolve to the dstpath', function (done) {
|
||||
const fs = util.fs();
|
||||
const contents = 'contents';
|
||||
|
||||
fs.mkdir('/dir', function(error) {
|
||||
if(error) throw error;
|
||||
fs.mkdir('/dir', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
fs.writeFile('/file', contents, function(error) {
|
||||
if(error) throw error;
|
||||
fs.writeFile('/file', contents, function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
fs.symlink('../file', '/dir/symlink', function(error) {
|
||||
if(error) throw error;
|
||||
fs.symlink('../file', '/dir/symlink', function (error) {
|
||||
if (error) throw error;
|
||||
|
||||
fs.readlink('/dir/symlink', function(error, result) {
|
||||
fs.readlink('/dir/symlink', function (error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.equal('../file');
|
||||
|
||||
fs.readFile('/dir/symlink', 'utf8', function(error, data) {
|
||||
fs.readFile('/dir/symlink', 'utf8', function (error, data) {
|
||||
expect(error).not.to.exist;
|
||||
expect(data).to.equal(contents);
|
||||
done();
|
||||
|
|
|
@ -20,7 +20,7 @@ describe('fs.rename', function() {
|
|||
if(error) throw error;
|
||||
|
||||
fs.rename('/myfile', '/myfile', function(error) {
|
||||
expect(error).not.to.exist;
|
||||
expect(error).not.to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -108,6 +108,35 @@ describe('fs.rename', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should rename an existing directory into another sub directory', () => {
|
||||
var fsPromises = util.fs().promises;
|
||||
|
||||
return fsPromises.mkdir('/mydir')
|
||||
.then(() => fsPromises.mkdir('/mydir/subdir'))
|
||||
.then(() => fsPromises.mkdir('/anotherdir'))
|
||||
.then(() => fsPromises.rename('/mydir', '/anotherdir/originaldir'))
|
||||
.then(() => { fsPromises.stat('/mydir')
|
||||
.catch((error) => {
|
||||
expect(error).to.exist;
|
||||
expect(error.code).to.equal('ENOENT');
|
||||
});
|
||||
})
|
||||
.then(() => { fsPromises.stat('/anotherdir/mydir')
|
||||
.catch((error) => {
|
||||
expect(error).to.exist;
|
||||
expect(error.code).to.equal('ENOENT');
|
||||
});
|
||||
})
|
||||
.then(() => { fsPromises.stat('/anotherdir/originaldir/subdir')
|
||||
.then(result => {
|
||||
expect(result.nlinks).to.equal(1);
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
if (error) throw error;
|
||||
});
|
||||
});
|
||||
|
||||
it('should rename an existing directory if the new path points to an existing directory', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
|
|
|
@ -1,26 +1,28 @@
|
|||
var Filer = require('../../src');
|
||||
var util = require('../lib/test-utils.js');
|
||||
var expect = require('chai').expect;
|
||||
'use strict';
|
||||
|
||||
const Filer = require('../../src');
|
||||
const util = require('../lib/test-utils.js');
|
||||
const expect = require('chai').expect;
|
||||
|
||||
describe('fs.Shell', function() {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('is a function', function() {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
expect(typeof fs.Shell).to.equal('function');
|
||||
});
|
||||
|
||||
it('should return a FileSystemShell instance', function() {
|
||||
var fs = util.fs();
|
||||
var sh = new fs.Shell();
|
||||
const fs = util.fs();
|
||||
const sh = new fs.Shell();
|
||||
|
||||
expect(sh.prototype).to.deep.equal((new Filer.Shell(fs)).prototype);
|
||||
});
|
||||
|
||||
it('should reflect changes to the prototype', function(){
|
||||
var fs = util.fs();
|
||||
var sh = new fs.Shell();
|
||||
const fs = util.fs();
|
||||
const sh = new fs.Shell();
|
||||
|
||||
Filer.Shell.prototype.test = 'foo';
|
||||
|
||||
|
|
|
@ -1,19 +1,21 @@
|
|||
var Filer = require('../../src');
|
||||
var util = require('../lib/test-utils.js');
|
||||
var expect = require('chai').expect;
|
||||
'use strict';
|
||||
|
||||
const Filer = require('../../src');
|
||||
const util = require('../lib/test-utils.js');
|
||||
const expect = require('chai').expect;
|
||||
|
||||
describe('fs', function() {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('is an object', function() {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
expect(typeof fs).to.equal('object');
|
||||
expect(fs).to.be.an.instanceof(Filer.FileSystem);
|
||||
});
|
||||
|
||||
it('should have a root directory', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
fs.stat('/', function(error, result) {
|
||||
expect(error).not.to.exist;
|
||||
expect(result).to.exist;
|
||||
|
|
|
@ -2,6 +2,7 @@ var util = require('../lib/test-utils.js');
|
|||
var chai = require('chai');
|
||||
chai.use(require('chai-datetime'));
|
||||
var expect = chai.expect;
|
||||
var Path = require('../../src').Path;
|
||||
|
||||
describe('fs.stat', function() {
|
||||
beforeEach(util.setup);
|
||||
|
@ -215,6 +216,291 @@ describe('fs.stat', function() {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('fs.stats', function() {
|
||||
describe('#isFile()', function() {
|
||||
|
||||
it('should be a function', function(done) {
|
||||
var fs = util.fs();
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isFile).to.be.a('function');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return true if stats are for file', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
fs.open('/myfile', 'w+', function(error, fd) {
|
||||
if(error) throw error;
|
||||
|
||||
fs.fstat(fd, function(error, stats) {
|
||||
expect(error).not.to.exist;
|
||||
expect(stats.isFile()).to.be.true;
|
||||
fs.close(fd, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false if stats are for directory', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isFile()).to.be.false;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false if stats are for symbolic link', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
fs.open('/myfile', 'w+', function(error, fd) {
|
||||
if(error) throw error;
|
||||
|
||||
fs.close(fd, function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
fs.symlink('/myfile', '/myfilelink', function(error) {
|
||||
if(error) throw error;
|
||||
fs.lstat('/myfilelink', function(error, stats) {
|
||||
expect(error).not.to.exist;
|
||||
expect(stats.isFile()).to.be.false;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isDirectory()', function() {
|
||||
|
||||
it('should be a function', function(done) {
|
||||
var fs = util.fs();
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isDirectory).to.be.a('function');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false if stats are for file', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
fs.open('/myfile', 'w+', function(error, fd) {
|
||||
if(error) throw error;
|
||||
fs.fstat(fd, function(error, stats) {
|
||||
expect(error).not.to.exist;
|
||||
expect(stats.isDirectory()).to.be.false;
|
||||
fs.close(fd, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should return true if stats are for directory', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isDirectory()).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false if stats are for symbolic link', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
fs.open('/myfile', 'w+', function(error, fd) {
|
||||
if(error) throw error;
|
||||
fs.close(fd, function(error) {
|
||||
if(error) throw error;
|
||||
fs.symlink('/myfile', '/myfilelink', function(error) {
|
||||
if(error) throw error;
|
||||
fs.lstat('/myfilelink', function(error, stats) {
|
||||
expect(stats.isDirectory()).to.be.false;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isBlockDevice()', function() {
|
||||
|
||||
it('should be a function', function(done) {
|
||||
var fs = util.fs();
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isBlockDevice).to.be.a('function');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false', function(done) {
|
||||
var fs = util.fs();
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isBlockDevice()).to.be.false;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isCharacterDevice()', function() {
|
||||
|
||||
it('should be a function', function(done) {
|
||||
var fs = util.fs();
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isCharacterDevice).to.be.a('function');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false', function(done) {
|
||||
var fs = util.fs();
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isCharacterDevice()).to.be.false;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isSymbolicLink()', function() {
|
||||
|
||||
it('should be a function', function(done) {
|
||||
var fs = util.fs();
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isSymbolicLink).to.be.a('function');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false if stats are for file', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
fs.open('/myfile', 'w+', function(error, fd) {
|
||||
if(error) throw error;
|
||||
fs.fstat(fd, function(error, stats) {
|
||||
expect(error).not.to.exist;
|
||||
expect(stats.isSymbolicLink()).to.be.false;
|
||||
fs.close(fd, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false if stats are for directory', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isSymbolicLink()).to.be.false;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return true if stats are for symbolic link', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
fs.open('/myfile', 'w+', function(error, fd) {
|
||||
if(error) throw error;
|
||||
fs.close(fd, function(error) {
|
||||
if(error) throw error;
|
||||
fs.symlink('/myfile', '/myfilelink', function(error) {
|
||||
if(error) throw error;
|
||||
fs.lstat('/myfilelink', function(error, stats) {
|
||||
expect(stats.isSymbolicLink()).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isFIFO()', function() {
|
||||
|
||||
it('should be a function', function(done) {
|
||||
var fs = util.fs();
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isFIFO).to.be.a('function');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false', function(done) {
|
||||
var fs = util.fs();
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isFIFO()).to.be.false;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isSocket()', function() {
|
||||
|
||||
it('should be a function', function(done) {
|
||||
var fs = util.fs();
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isSocket).to.be.a('function');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false', function(done) {
|
||||
var fs = util.fs();
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isSocket()).to.be.false;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('generated name property', function() {
|
||||
|
||||
it('should correct return name for a file', function(done) {
|
||||
var fs = util.fs();
|
||||
var filepath = '/a';
|
||||
|
||||
fs.writeFile(filepath, 'data', function(err) {
|
||||
if(err) throw err;
|
||||
|
||||
fs.stat(filepath, function(err, stats) {
|
||||
if(err) throw err;
|
||||
|
||||
expect(stats.name).to.equal(Path.basename(filepath));
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should correct return name for an fd', function(done) {
|
||||
var fs = util.fs();
|
||||
var filepath = '/a';
|
||||
|
||||
fs.open(filepath, 'w', function(err, fd) {
|
||||
if(err) throw err;
|
||||
|
||||
fs.fstat(fd, function(err, stats) {
|
||||
if(err) throw err;
|
||||
|
||||
expect(stats.name).to.equal(Path.basename(filepath));
|
||||
fs.close(fd, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,303 +0,0 @@
|
|||
var Path = require('../../src').Path;
|
||||
var util = require('../lib/test-utils.js');
|
||||
var expect = require('chai').expect;
|
||||
|
||||
describe('fs.stats', function() {
|
||||
describe('#isFile()', function() {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function(done) {
|
||||
var fs = util.fs();
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isFile).to.be.a('function');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return true if stats are for file', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
fs.open('/myfile', 'w+', function(error, fd) {
|
||||
if(error) throw error;
|
||||
|
||||
fs.fstat(fd, function(error, stats) {
|
||||
expect(error).not.to.exist;
|
||||
expect(stats.isFile()).to.be.true;
|
||||
fs.close(fd, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false if stats are for directory', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isFile()).to.be.false;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false if stats are for symbolic link', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
fs.open('/myfile', 'w+', function(error, fd) {
|
||||
if(error) throw error;
|
||||
|
||||
fs.close(fd, function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
fs.symlink('/myfile', '/myfilelink', function(error) {
|
||||
if(error) throw error;
|
||||
fs.lstat('/myfilelink', function(error, stats) {
|
||||
expect(error).not.to.exist;
|
||||
expect(stats.isFile()).to.be.false;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isDirectory()', function() {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function(done) {
|
||||
var fs = util.fs();
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isDirectory).to.be.a('function');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false if stats are for file', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
fs.open('/myfile', 'w+', function(error, fd) {
|
||||
if(error) throw error;
|
||||
fs.fstat(fd, function(error, stats) {
|
||||
expect(error).not.to.exist;
|
||||
expect(stats.isDirectory()).to.be.false;
|
||||
fs.close(fd, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should return true if stats are for directory', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isDirectory()).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false if stats are for symbolic link', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
fs.open('/myfile', 'w+', function(error, fd) {
|
||||
if(error) throw error;
|
||||
fs.close(fd, function(error) {
|
||||
if(error) throw error;
|
||||
fs.symlink('/myfile', '/myfilelink', function(error) {
|
||||
if(error) throw error;
|
||||
fs.lstat('/myfilelink', function(error, stats) {
|
||||
expect(stats.isDirectory()).to.be.false;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isBlockDevice()', function() {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function(done) {
|
||||
var fs = util.fs();
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isBlockDevice).to.be.a('function');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false', function(done) {
|
||||
var fs = util.fs();
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isBlockDevice()).to.be.false;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isCharacterDevice()', function() {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function(done) {
|
||||
var fs = util.fs();
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isCharacterDevice).to.be.a('function');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false', function(done) {
|
||||
var fs = util.fs();
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isCharacterDevice()).to.be.false;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isSymbolicLink()', function() {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function(done) {
|
||||
var fs = util.fs();
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isSymbolicLink).to.be.a('function');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false if stats are for file', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
fs.open('/myfile', 'w+', function(error, fd) {
|
||||
if(error) throw error;
|
||||
fs.fstat(fd, function(error, stats) {
|
||||
expect(error).not.to.exist;
|
||||
expect(stats.isSymbolicLink()).to.be.false;
|
||||
fs.close(fd, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false if stats are for directory', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isSymbolicLink()).to.be.false;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return true if stats are for symbolic link', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
fs.open('/myfile', 'w+', function(error, fd) {
|
||||
if(error) throw error;
|
||||
fs.close(fd, function(error) {
|
||||
if(error) throw error;
|
||||
fs.symlink('/myfile', '/myfilelink', function(error) {
|
||||
if(error) throw error;
|
||||
fs.lstat('/myfilelink', function(error, stats) {
|
||||
expect(stats.isSymbolicLink()).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isFIFO()', function() {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function(done) {
|
||||
var fs = util.fs();
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isFIFO).to.be.a('function');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false', function(done) {
|
||||
var fs = util.fs();
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isFIFO()).to.be.false;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isSocket()', function() {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function(done) {
|
||||
var fs = util.fs();
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isSocket).to.be.a('function');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false', function(done) {
|
||||
var fs = util.fs();
|
||||
fs.stat('/', function(error, stats) {
|
||||
if(error) throw error;
|
||||
expect(stats.isSocket()).to.be.false;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('generated name property', function() {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should correct return name for a file', function(done) {
|
||||
var fs = util.fs();
|
||||
var filepath = '/a';
|
||||
|
||||
fs.writeFile(filepath, 'data', function(err) {
|
||||
if(err) throw err;
|
||||
|
||||
fs.stat(filepath, function(err, stats) {
|
||||
if(err) throw err;
|
||||
|
||||
expect(stats.name).to.equal(Path.basename(filepath));
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should correct return name for an fd', function(done) {
|
||||
var fs = util.fs();
|
||||
var filepath = '/a';
|
||||
|
||||
fs.open(filepath, 'w', function(err, fd) {
|
||||
if(err) throw err;
|
||||
|
||||
fs.fstat(fd, function(err, stats) {
|
||||
if(err) throw err;
|
||||
|
||||
expect(stats.name).to.equal(Path.basename(filepath));
|
||||
fs.close(fd, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,18 +1,18 @@
|
|||
var util = require('../lib/test-utils.js');
|
||||
var expect = require('chai').expect;
|
||||
let util = require('../lib/test-utils.js');
|
||||
let expect = require('chai').expect;
|
||||
|
||||
describe('fs.unlink', function() {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
expect(fs.unlink).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should remove a link to an existing file', function(done) {
|
||||
var fs = util.fs();
|
||||
var complete1, complete2;
|
||||
let fs = util.fs();
|
||||
let complete1, complete2;
|
||||
|
||||
function maybeDone() {
|
||||
if(complete1 && complete2) {
|
||||
|
@ -53,7 +53,7 @@ describe('fs.unlink', function() {
|
|||
});
|
||||
|
||||
it('should not follow symbolic links', function(done) {
|
||||
var fs = util.fs();
|
||||
let fs = util.fs();
|
||||
|
||||
fs.symlink('/', '/myFileLink', function (error) {
|
||||
if (error) throw error;
|
||||
|
@ -85,7 +85,7 @@ describe('fs.unlink', function() {
|
|||
});
|
||||
|
||||
it('should not unlink directories', function (done) {
|
||||
var fs = util.fs();
|
||||
let fs = util.fs();
|
||||
|
||||
fs.mkdir('/mydir', function (error) {
|
||||
if(error) throw error;
|
||||
|
@ -110,12 +110,12 @@ describe('fs.promises.unlink', function () {
|
|||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function () {
|
||||
var fs = util.fs();
|
||||
let fs = util.fs();
|
||||
expect(fs.promises.unlink).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should return an error if trying to delete a file that does not exist', function() {
|
||||
var fsPromises = util.fs().promises;
|
||||
const fsPromises = util.fs().promises;
|
||||
|
||||
return fsPromises.unlink('/myFile')
|
||||
.catch(error => {
|
||||
|
@ -125,7 +125,7 @@ describe('fs.promises.unlink', function () {
|
|||
});
|
||||
|
||||
it('should not unlink directories', () => {
|
||||
var fs = util.fs().promises;
|
||||
let fs = util.fs().promises;
|
||||
|
||||
return fs.mkdir('/mydir')
|
||||
.then(() => fs.unlink('/mydir'))
|
||||
|
|
|
@ -65,4 +65,49 @@ describe('fs.write', function() {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail if given a file path vs. an fd', function(done) {
|
||||
const fs = util.fs();
|
||||
const buffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
|
||||
fs.write('/myfile', buffer, 0, buffer.length, 0, function(error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.code).to.equal('EBADF');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail when trying to write more bytes than are available in the buffer (length too long)', function(done) {
|
||||
const fs = util.fs();
|
||||
const buffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
|
||||
fs.open('/myfile', 'w', function(error, fd) {
|
||||
if(error) throw error;
|
||||
|
||||
fs.write(fd, buffer, 0, (buffer.length + 10), 0, function(error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.code).to.equal('EIO');
|
||||
fs.close(fd, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail to write data to a file opened without the O_WRITE flag', function(done) {
|
||||
const fs = util.fs();
|
||||
const buffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
|
||||
fs.mknod('/myfile', 'FILE', function(err) {
|
||||
if (err) throw err;
|
||||
|
||||
fs.open('/myfile', 'r', function(error, fd) {
|
||||
if(error) throw error;
|
||||
|
||||
fs.write(fd, buffer, 0, buffer.length, 0, function(error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.code).to.equal('EBADF');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
var util = require('../lib/test-utils.js');
|
||||
var expect = require('chai').expect;
|
||||
'use strict';
|
||||
const util = require('../lib/test-utils.js');
|
||||
const expect = require('chai').expect;
|
||||
|
||||
describe('fs.writeFile, fs.readFile', function() {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
expect(fs.writeFile).to.be.a('function');
|
||||
expect(fs.readFile).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should error when path is wrong to readFile', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
fs.readFile('/no-such-file', 'utf8', function(error, data) {
|
||||
expect(error).to.exist;
|
||||
|
@ -24,7 +25,7 @@ describe('fs.writeFile, fs.readFile', function() {
|
|||
|
||||
|
||||
it('should error when path is wrong to writeFile',function(done){
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
fs.writeFile('/tmp/myfile', '','utf8', function(error, result) {
|
||||
expect(error).to.exist;
|
||||
|
@ -36,8 +37,8 @@ describe('fs.writeFile, fs.readFile', function() {
|
|||
});
|
||||
|
||||
it('should write, read a utf8 file without specifying utf8 in writeFile', function(done) {
|
||||
var fs = util.fs();
|
||||
var contents = 'This is a file.';
|
||||
const fs = util.fs();
|
||||
const contents = 'This is a file.';
|
||||
|
||||
fs.writeFile('/myfile', contents, function(error) {
|
||||
if(error) throw error;
|
||||
|
@ -50,8 +51,8 @@ describe('fs.writeFile, fs.readFile', function() {
|
|||
});
|
||||
|
||||
it('should write, read a utf8 file with "utf8" option to writeFile', function(done) {
|
||||
var fs = util.fs();
|
||||
var contents = 'This is a file.';
|
||||
const fs = util.fs();
|
||||
const contents = 'This is a file.';
|
||||
|
||||
fs.writeFile('/myfile', contents, 'utf8', function(error) {
|
||||
if(error) throw error;
|
||||
|
@ -64,8 +65,8 @@ describe('fs.writeFile, fs.readFile', function() {
|
|||
});
|
||||
|
||||
it('should write, read a utf8 file with {encoding: "utf8"} option to writeFile', function(done) {
|
||||
var fs = util.fs();
|
||||
var contents = 'This is a file.';
|
||||
const fs = util.fs();
|
||||
const contents = 'This is a file.';
|
||||
|
||||
fs.writeFile('/myfile', contents, { encoding: 'utf8' }, function(error) {
|
||||
if(error) throw error;
|
||||
|
@ -78,9 +79,9 @@ describe('fs.writeFile, fs.readFile', function() {
|
|||
});
|
||||
|
||||
it('should write, read a binary file', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
// String and utf8 binary encoded versions of the same thing: 'This is a file.'
|
||||
var binary = Buffer.from([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46]);
|
||||
const binary = Buffer.from([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46]);
|
||||
|
||||
fs.writeFile('/myfile', binary, function(error) {
|
||||
if(error) throw error;
|
||||
|
@ -93,8 +94,8 @@ describe('fs.writeFile, fs.readFile', function() {
|
|||
});
|
||||
|
||||
it('should follow symbolic links', function(done) {
|
||||
var fs = util.fs();
|
||||
var contents = 'This is a file.';
|
||||
const fs = util.fs();
|
||||
const contents = 'This is a file.';
|
||||
|
||||
fs.writeFile('/myfile', '', { encoding: 'utf8' }, function(error) {
|
||||
if(error) throw error;
|
||||
|
@ -122,16 +123,16 @@ describe('fsPromises.writeFile, fsPromises.readFile', function() {
|
|||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
var fsPromises = util.fs().promises;
|
||||
const fsPromises = util.fs().promises;
|
||||
expect(fsPromises.writeFile).to.be.a('function');
|
||||
expect(fsPromises.readFile).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should return a promise', function() {
|
||||
var fsPromises = util.fs().promises;
|
||||
var contents = 'This is a file.';
|
||||
const fsPromises = util.fs().promises;
|
||||
const contents = 'This is a file.';
|
||||
|
||||
var p = fsPromises.writeFile('/myfile', contents);
|
||||
const p = fsPromises.writeFile('/myfile', contents);
|
||||
expect(p).to.be.a('Promise');
|
||||
|
||||
p.then(() => {
|
||||
|
@ -141,7 +142,7 @@ describe('fsPromises.writeFile, fsPromises.readFile', function() {
|
|||
});
|
||||
|
||||
it('should error when path is wrong to readFile', function() {
|
||||
var fsPromises = util.fs().promises;
|
||||
const fsPromises = util.fs().promises;
|
||||
|
||||
return fsPromises.readFile('/no-such-file', 'utf8')
|
||||
.catch(error => {
|
||||
|
@ -151,8 +152,8 @@ describe('fsPromises.writeFile, fsPromises.readFile', function() {
|
|||
});
|
||||
|
||||
it('should write, read a utf8 file without specifying utf8 in writeFile', function() {
|
||||
var fsPromises = util.fs().promises;
|
||||
var contents = 'This is a file.';
|
||||
const fsPromises = util.fs().promises;
|
||||
const contents = 'This is a file.';
|
||||
|
||||
return fsPromises.writeFile('/myfile', contents)
|
||||
.then( () => fsPromises.readFile('/myfile', 'utf8'))
|
||||
|
@ -160,8 +161,8 @@ describe('fsPromises.writeFile, fsPromises.readFile', function() {
|
|||
});
|
||||
|
||||
it('should write, read a utf8 file with "utf8" option to writeFile', function() {
|
||||
var fsPromises = util.fs().promises;
|
||||
var contents = 'This is a file.';
|
||||
const fsPromises = util.fs().promises;
|
||||
const contents = 'This is a file.';
|
||||
|
||||
return fsPromises.writeFile('/myfile', contents, 'utf8')
|
||||
.then( () => fsPromises.readFile('/myfile', 'utf8'))
|
||||
|
@ -169,8 +170,8 @@ describe('fsPromises.writeFile, fsPromises.readFile', function() {
|
|||
});
|
||||
|
||||
it('should write, read a utf8 file with {encoding: "utf8"} option to writeFile', function() {
|
||||
var fsPromises = util.fs().promises;
|
||||
var contents = 'This is a file.';
|
||||
const fsPromises = util.fs().promises;
|
||||
const contents = 'This is a file.';
|
||||
|
||||
return fsPromises.writeFile('/myfile', contents, { encoding: 'utf8' })
|
||||
.then( () => fsPromises.readFile('/myfile', 'utf8'))
|
||||
|
@ -178,9 +179,9 @@ describe('fsPromises.writeFile, fsPromises.readFile', function() {
|
|||
});
|
||||
|
||||
it('should write, read a binary file', function() {
|
||||
var fsPromises = util.fs().promises;
|
||||
const fsPromises = util.fs().promises;
|
||||
// String and utf8 binary encoded versions of the same thing: 'This is a file.'
|
||||
var binary = Buffer.from([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46]);
|
||||
const binary = Buffer.from([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46]);
|
||||
|
||||
return fsPromises.writeFile('/myfile', binary)
|
||||
.then( () => fsPromises.readFile('/myfile'))
|
||||
|
@ -188,8 +189,8 @@ describe('fsPromises.writeFile, fsPromises.readFile', function() {
|
|||
});
|
||||
|
||||
it('should follow symbolic links', function() {
|
||||
var fsPromises = util.fs().promises;
|
||||
var contents = 'This is a file.';
|
||||
const fsPromises = util.fs().promises;
|
||||
const contents = 'This is a file.';
|
||||
|
||||
return fsPromises.writeFile('/myfile', '', { encoding: 'utf8' })
|
||||
.then( () => fsPromises.symlink('/myfile', '/myFileLink'))
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
var util = require('../lib/test-utils.js');
|
||||
var expect = require('chai').expect;
|
||||
'use strict';
|
||||
|
||||
const util = require('../lib/test-utils.js');
|
||||
const expect = require('chai').expect;
|
||||
|
||||
describe('fs.xattr', function() {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function () {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
expect(fs.setxattr).to.be.a('function');
|
||||
expect(fs.getxattr).to.be.a('function');
|
||||
expect(fs.removexattr).to.be.a('function');
|
||||
|
@ -15,7 +17,7 @@ describe('fs.xattr', function() {
|
|||
});
|
||||
|
||||
it('should error when setting with a name that is not a string', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
fs.writeFile('/testfile', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
@ -29,7 +31,7 @@ describe('fs.xattr', function() {
|
|||
});
|
||||
|
||||
it('should error when setting with a name that is null', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
fs.writeFile('/testfile', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
@ -43,7 +45,7 @@ describe('fs.xattr', function() {
|
|||
});
|
||||
|
||||
it('should error when setting with an invalid flag', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
fs.writeFile('/testfile', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
@ -57,7 +59,7 @@ describe('fs.xattr', function() {
|
|||
});
|
||||
|
||||
it('should error when when setting an extended attribute which exists with XATTR_CREATE flag', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
fs.writeFile('/testfile', '', function(error) {
|
||||
if (error) throw error;
|
||||
|
@ -75,7 +77,7 @@ describe('fs.xattr', function() {
|
|||
});
|
||||
|
||||
it('should error when setting an extended attribute which does not exist with XATTR_REPLACE flag', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
fs.writeFile('/testfile', '', function(error) {
|
||||
if (error) throw error;
|
||||
|
@ -89,7 +91,7 @@ describe('fs.xattr', function() {
|
|||
});
|
||||
|
||||
it('should error when getting an attribute with a name that is empty', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
fs.writeFile('/testfile', '', function(error) {
|
||||
if (error) throw error;
|
||||
|
@ -104,7 +106,7 @@ describe('fs.xattr', function() {
|
|||
});
|
||||
|
||||
it('should error when getting an attribute where the name is not a string', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
fs.writeFile('/testfile', '', function(error) {
|
||||
if (error) throw error;
|
||||
|
@ -119,7 +121,7 @@ describe('fs.xattr', function() {
|
|||
});
|
||||
|
||||
it('should error when getting an attribute that does not exist', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
fs.writeFile('/testfile', '', function(error) {
|
||||
if (error) throw error;
|
||||
|
@ -134,10 +136,10 @@ describe('fs.xattr', function() {
|
|||
});
|
||||
|
||||
it('should error when file descriptor is invalid', function(done) {
|
||||
var fs = util.fs();
|
||||
var completeSet = false;
|
||||
var completeGet = false;
|
||||
var completeRemove = false;
|
||||
const fs = util.fs();
|
||||
let completeSet = false;
|
||||
let completeGet = false;
|
||||
let completeRemove = false;
|
||||
|
||||
function maybeDone() {
|
||||
if(completeSet && completeGet && completeRemove) {
|
||||
|
@ -170,8 +172,8 @@ describe('fs.xattr', function() {
|
|||
});
|
||||
|
||||
it('should set and get an extended attribute of a path', function(done) {
|
||||
var fs = util.fs();
|
||||
var name = 'test';
|
||||
const fs = util.fs();
|
||||
const name = 'test';
|
||||
|
||||
fs.writeFile('/testfile', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
@ -189,7 +191,7 @@ describe('fs.xattr', function() {
|
|||
});
|
||||
|
||||
it('should error when attempting to remove a non-existing attribute', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
fs.writeFile('/testfile', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
@ -207,7 +209,7 @@ describe('fs.xattr', function() {
|
|||
});
|
||||
|
||||
it('should set and get an empty string as a value', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
fs.writeFile('/testfile', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
@ -225,7 +227,7 @@ describe('fs.xattr', function() {
|
|||
});
|
||||
|
||||
it('should set and get an extended attribute for a valid file descriptor', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
fs.open('/testfile', 'w', function (error, ofd) {
|
||||
if (error) throw error;
|
||||
|
@ -243,7 +245,7 @@ describe('fs.xattr', function() {
|
|||
});
|
||||
|
||||
it('should set and get an object to an extended attribute', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
fs.writeFile('/testfile', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
@ -261,7 +263,7 @@ describe('fs.xattr', function() {
|
|||
});
|
||||
|
||||
it('should update/overwrite an existing extended attribute', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
fs.writeFile('/testfile', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
@ -296,7 +298,7 @@ describe('fs.xattr', function() {
|
|||
});
|
||||
|
||||
it('should set multiple extended attributes for a path', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
fs.writeFile('/testfile', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
@ -323,7 +325,7 @@ describe('fs.xattr', function() {
|
|||
});
|
||||
|
||||
it('should remove an extended attribute from a path', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
fs.writeFile('/testfile', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
@ -350,7 +352,7 @@ describe('fs.xattr', function() {
|
|||
});
|
||||
|
||||
it('should remove an extended attribute from a valid file descriptor', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
fs.open('/testfile', 'w', function (error, ofd) {
|
||||
if (error) throw error;
|
||||
|
@ -377,7 +379,7 @@ describe('fs.xattr', function() {
|
|||
});
|
||||
|
||||
it('should allow setting with a null value', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
fs.writeFile('/testfile', '', function (error) {
|
||||
if (error) throw error;
|
||||
|
@ -393,4 +395,4 @@ describe('fs.xattr', function() {
|
|||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -30,6 +30,18 @@ describe('FileSystemShell.mkdirp', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should succeed if provided path is root, given as a relative path (\'.\' in \'/\')', function(done) {
|
||||
var fs = util.fs();
|
||||
var shell = new fs.Shell();
|
||||
shell.cd('/', function(err) {
|
||||
expect(err).to.not.exist;
|
||||
shell.mkdirp('.', function(err) {
|
||||
expect(err).to.not.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should succeed if the directory exists', function(done) {
|
||||
var fs = util.fs();
|
||||
var shell = new fs.Shell();
|
||||
|
@ -67,6 +79,21 @@ describe('FileSystemShell.mkdirp', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should succeed on a folder given as a relative path (\'test\' in \'/\')', function(done) {
|
||||
var fs = util.fs();
|
||||
var shell = new fs.Shell();
|
||||
shell.cd('/', function(err) {
|
||||
expect(err).to.not.exist;
|
||||
shell.mkdirp('test', function(err) {
|
||||
expect(err).to.not.exist;
|
||||
fs.exists('/test', function(dir){
|
||||
expect(dir).to.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should succeed on a folder with a nonexistant parent (\'/test/test\')', function(done) {
|
||||
var fs = util.fs();
|
||||
var shell = new fs.Shell();
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
'use strict';
|
||||
const expect = require('chai').expect;
|
||||
const utils = require('../../lib/test-utils');
|
||||
const fs = utils.shimIndexedDB(() => require('../../../shims/fs'));
|
||||
|
||||
describe('fs shim', () => {
|
||||
it('should be defined', () => {
|
||||
expect(fs).to.not.be.undefined;
|
||||
});
|
||||
|
||||
it('should be an object', () => {
|
||||
expect(typeof fs).to.equal('object');
|
||||
});
|
||||
|
||||
it('should return a function when accessing fs.writeFile', () => {
|
||||
expect(typeof fs.writeFile).to.equal('function');
|
||||
});
|
||||
|
||||
it('should call callback when calling fs.writeFile', (done) => {
|
||||
fs.writeFile('/test.txt', 'test', function(err) {
|
||||
if(err) throw err;
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an object when accessing fs.promises', () => {
|
||||
expect(typeof fs.promises).to.equal('object');
|
||||
});
|
||||
|
||||
it('should return a function when accessing fs.promises.writeFile', () => {
|
||||
expect(typeof fs.promises.writeFile).to.equal('function');
|
||||
});
|
||||
|
||||
it('should return a promise which resolves when calling fs.promises.writeFile', (done) => {
|
||||
const writeFilePromise = fs.promises.writeFile('/test2.txt', '');
|
||||
expect(writeFilePromise instanceof Promise).to.equal(true);
|
||||
writeFilePromise.then(() => {
|
||||
done();
|
||||
}).catch((err) => {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
'use strict';
|
||||
const expect = require('chai').expect;
|
||||
const path = require('../../../shims/path');
|
||||
const pathActual = require('../../../src/index').path;
|
||||
|
||||
describe('path shim', () => {
|
||||
it('should be defined', () => {
|
||||
expect(path).to.not.be.undefined;
|
||||
});
|
||||
|
||||
it('should be re-exposing path', () => {
|
||||
expect(path).to.equal(pathActual);
|
||||
});
|
||||
});
|
|
@ -1,15 +1,16 @@
|
|||
var util = require('../lib/test-utils.js');
|
||||
var expect = require('chai').expect;
|
||||
'use strict';
|
||||
const util = require('../lib/test-utils.js');
|
||||
const expect = require('chai').expect;
|
||||
|
||||
describe('node times (atime, mtime, ctimeMs)', function() {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
var dirname = '/dir';
|
||||
var filename = '/dir/file';
|
||||
const dirname = '/dir';
|
||||
const filename = '/dir/file';
|
||||
|
||||
function createTree(callback) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
fs.mkdir(dirname, function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
|
@ -22,7 +23,7 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
}
|
||||
|
||||
function stat(path, callback) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
fs.stat(path, function(error, stats) {
|
||||
if(error) throw error;
|
||||
|
||||
|
@ -31,8 +32,8 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
}
|
||||
|
||||
it('should update ctime when calling fs.rename()', function(done) {
|
||||
var fs = util.fs();
|
||||
var newfilename = filename + '1';
|
||||
const fs = util.fs();
|
||||
const newfilename = filename + '1';
|
||||
|
||||
createTree(function() {
|
||||
stat(filename, function(stats1) {
|
||||
|
@ -52,7 +53,7 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
});
|
||||
|
||||
it('should update ctime, mtime, atime when calling fs.truncate()', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
createTree(function() {
|
||||
stat(filename, function(stats1) {
|
||||
|
@ -72,7 +73,7 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
});
|
||||
|
||||
it('should update ctime, mtime, atime when calling fs.ftruncate()', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
createTree(function() {
|
||||
stat(filename, function(stats1) {
|
||||
|
@ -97,7 +98,7 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
});
|
||||
|
||||
it('should make no change when calling fs.stat()', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
createTree(function() {
|
||||
stat(filename, function(stats1) {
|
||||
|
@ -115,7 +116,7 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
});
|
||||
|
||||
it('should make no change when calling fs.fstat()', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
createTree(function() {
|
||||
stat(filename, function(stats1) {
|
||||
|
@ -138,7 +139,7 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
});
|
||||
|
||||
it('should make no change when calling fs.lstat()', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
createTree(function() {
|
||||
fs.link(filename, '/link', function(error) {
|
||||
|
@ -159,7 +160,7 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
});
|
||||
|
||||
it('should make no change when calling fs.exists()', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
createTree(function() {
|
||||
stat(filename, function(stats1) {
|
||||
|
@ -181,7 +182,7 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
});
|
||||
|
||||
it('should update ctime, atime when calling fs.link()', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
createTree(function() {
|
||||
stat(filename, function(stats1) {
|
||||
|
@ -200,7 +201,7 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
});
|
||||
|
||||
it('should make no change when calling fs.symlink()', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
createTree(function() {
|
||||
stat(filename, function(stats1) {
|
||||
|
@ -219,7 +220,7 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
});
|
||||
|
||||
it('should make no change when calling fs.readlink()', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
createTree(function() {
|
||||
fs.symlink(filename, '/link', function(error) {
|
||||
|
@ -243,7 +244,7 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
});
|
||||
|
||||
it('should update ctime, atime, mtime of parent dir when calling fs.unlink()', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
createTree(function() {
|
||||
stat(dirname, function(stats1) {
|
||||
|
@ -262,7 +263,7 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
});
|
||||
|
||||
it('should update ctime, atime, mtime of parent dir when calling fs.rmdir()', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
createTree(function() {
|
||||
stat('/', function(stats1) {
|
||||
|
@ -286,7 +287,7 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
});
|
||||
|
||||
it('should update ctime, atime, mtime of parent dir when calling fs.mkdir()', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
createTree(function() {
|
||||
stat('/', function(stats1) {
|
||||
|
@ -306,7 +307,7 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
});
|
||||
|
||||
it('should make no change when calling fs.close()', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
createTree(function() {
|
||||
fs.open(filename, 'w', function(error, fd) {
|
||||
|
@ -329,7 +330,7 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
});
|
||||
|
||||
it('should make no change when calling fs.open()', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
createTree(function() {
|
||||
stat(filename, function(stats1) {
|
||||
|
@ -353,8 +354,8 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
*/
|
||||
|
||||
it('should update atime, ctime, mtime when calling fs.write()', function(done) {
|
||||
var fs = util.fs();
|
||||
var buffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
const fs = util.fs();
|
||||
const buffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
|
||||
createTree(function() {
|
||||
fs.open('/myfile', 'w', function(error, fd) {
|
||||
|
@ -382,8 +383,8 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
});
|
||||
|
||||
it('should make no change when calling fs.read()', function(done) {
|
||||
var fs = util.fs();
|
||||
var buffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
const fs = util.fs();
|
||||
const buffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
|
||||
createTree(function() {
|
||||
fs.open('/myfile', 'w', function(err, fd) {
|
||||
|
@ -400,7 +401,7 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
if(error) throw error;
|
||||
|
||||
stat('/myfile', function(stats1) {
|
||||
var buffer2 = Buffer.alloc(buffer.length);
|
||||
const buffer2 = Buffer.alloc(buffer.length);
|
||||
|
||||
fs.read(fd, buffer2, 0, buffer2.length, 0, function(err, nbytes) {
|
||||
if(err) throw err;
|
||||
|
@ -426,7 +427,7 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
});
|
||||
|
||||
it('should make no change when calling fs.readFile()', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
createTree(function() {
|
||||
stat(filename, function(stats1) {
|
||||
|
@ -446,7 +447,7 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
});
|
||||
|
||||
it('should update atime, ctime, mtime when calling fs.writeFile()', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
createTree(function() {
|
||||
stat(filename, function(stats1) {
|
||||
|
@ -465,7 +466,7 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
});
|
||||
|
||||
it('should update atime, ctime, mtime when calling fs.appendFile()', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
createTree(function() {
|
||||
stat(filename, function(stats1) {
|
||||
|
@ -484,7 +485,7 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
});
|
||||
|
||||
it('should update ctime, atime when calling fs.setxattr()', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
createTree(function() {
|
||||
stat(filename, function(stats1) {
|
||||
|
@ -503,7 +504,7 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
});
|
||||
|
||||
it('should update ctime, atime when calling fs.fsetxattr()', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
createTree(function() {
|
||||
fs.open(filename, 'w', function(error, fd) {
|
||||
|
@ -526,7 +527,7 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
});
|
||||
|
||||
it('should make no change when calling fs.getxattr()', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
createTree(function() {
|
||||
fs.setxattr(filename, 'extra', 'data', function(error) {
|
||||
|
@ -550,7 +551,7 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
});
|
||||
|
||||
it('should make no change when calling fs.fgetxattr()', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
createTree(function() {
|
||||
fs.open(filename, 'w', function(error, fd) {
|
||||
|
@ -578,7 +579,7 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
});
|
||||
|
||||
it('should update ctime, atime when calling fs.removexattr()', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
createTree(function() {
|
||||
fs.setxattr(filename, 'extra', 'data', function(error) {
|
||||
|
@ -601,7 +602,7 @@ describe('node times (atime, mtime, ctimeMs)', function() {
|
|||
});
|
||||
|
||||
it('should update ctime, atime when calling fs.fremovexattr()', function(done) {
|
||||
var fs = util.fs();
|
||||
const fs = util.fs();
|
||||
|
||||
createTree(function() {
|
||||
fs.open(filename, 'w', function(error, fd) {
|
||||
|
|
|
@ -0,0 +1,528 @@
|
|||
'use strict';
|
||||
const expect = require('chai').expect;
|
||||
const utils = require('../../lib/test-utils');
|
||||
const FilerWebpackPlugin = require('../../../src/webpack-plugin');
|
||||
|
||||
function createNMFResolveCompilerObject(resolveData) {
|
||||
|
||||
const normalModuleFactory_resolve_tap = utils.createMockFn(function (name, callback) {
|
||||
callback(resolveData);
|
||||
});
|
||||
|
||||
const normalModuleFactory = {
|
||||
hooks: {
|
||||
resolve: {
|
||||
tap: normalModuleFactory_resolve_tap
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const normalModuleFactory_tap = utils.createMockFn(function (name, callback) {
|
||||
callback(normalModuleFactory);
|
||||
});
|
||||
|
||||
const compiler = {
|
||||
hooks: {
|
||||
normalModuleFactory: {
|
||||
tap: normalModuleFactory_tap,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
compiler,
|
||||
normalModuleFactory_tap,
|
||||
normalModuleFactory_resolve_tap,
|
||||
};
|
||||
}
|
||||
|
||||
describe('path shim', () => {
|
||||
it('should instantiate the plugin with valid options', () => {
|
||||
// Arrange
|
||||
const options = {
|
||||
filerDir: '/filer',
|
||||
shimsDir: '/shims',
|
||||
fsProviderDir: '/fsProvider',
|
||||
shimFs: false,
|
||||
shimPath: false,
|
||||
fsProvider: 'custom',
|
||||
};
|
||||
|
||||
// Act
|
||||
const plugin = new FilerWebpackPlugin(options);
|
||||
|
||||
// Assert
|
||||
expect(plugin.options).to.not.be.undefined;
|
||||
|
||||
expect(plugin.options.filerDir).to.equal(options.filerDir);
|
||||
expect(plugin.options.shimsDir).to.equal(options.shimsDir);
|
||||
expect(plugin.options.fsProviderDir).to.equal(options.fsProviderDir);
|
||||
expect(plugin.options.shimFs).to.equal(options.shimFs);
|
||||
expect(plugin.options.shimPath).to.equal(options.shimPath);
|
||||
expect(plugin.options.fsProvider).to.equal(options.fsProvider);
|
||||
});
|
||||
|
||||
it('should instantiate the plugin with default options', () => {
|
||||
// Act
|
||||
const plugin = new FilerWebpackPlugin();
|
||||
|
||||
// Assert
|
||||
expect(plugin.options).to.not.be.undefined;
|
||||
|
||||
expect(plugin.options.filerDir).to.equal('/node_modules/filer');
|
||||
expect(plugin.options.shimsDir).to.equal('/node_modules/filer/shims');
|
||||
expect(plugin.options.fsProviderDir).to.equal('/node_modules/filer/shims/providers');
|
||||
expect(plugin.options.shimFs).to.equal(true);
|
||||
expect(plugin.options.shimPath).to.equal(true);
|
||||
expect(plugin.options.fsProvider).to.equal('default');
|
||||
});
|
||||
|
||||
it('should throw if provided invalid options', () => {
|
||||
// Arrange
|
||||
const options = {
|
||||
filerDir: 123,
|
||||
shimsDir: 456,
|
||||
fsProviderDir: 789,
|
||||
shimFs: 'false',
|
||||
shimPath: 'false',
|
||||
fsProvider: false,
|
||||
};
|
||||
|
||||
// Act // Assert
|
||||
expect(() => {
|
||||
new FilerWebpackPlugin(options);
|
||||
}).to.throw();
|
||||
});
|
||||
|
||||
it('should instantiate the plugin with options and the <rootDir> tag should be replaced', () => {
|
||||
// Arrange
|
||||
const options = {
|
||||
filerDir: '<rootDir>/filer',
|
||||
shimsDir: '<rootDir>/shims',
|
||||
fsProviderDir: '<rootDir>/fsProvider',
|
||||
};
|
||||
|
||||
// Act
|
||||
const plugin = new FilerWebpackPlugin(options);
|
||||
|
||||
// Assert
|
||||
expect(plugin.options).to.not.be.undefined;
|
||||
|
||||
expect(plugin.options.filerDir).to.equal(options.filerDir.replace('<rootDir>', ''));
|
||||
expect(plugin.options.shimsDir).to.equal(options.shimsDir.replace('<rootDir>', ''));
|
||||
expect(plugin.options.fsProviderDir).to.equal(options.fsProviderDir.replace('<rootDir>', ''));
|
||||
});
|
||||
|
||||
describe('should instantiate the plugin with valid options and invoke the apply method', () => {
|
||||
it('should ignore an unrelated module', () => {
|
||||
// Arrange
|
||||
const options = {
|
||||
filerDir: '/filer',
|
||||
shimsDir: '/shims',
|
||||
fsProviderDir: '/fsProvider',
|
||||
shimFs: false,
|
||||
shimPath: false,
|
||||
fsProvider: 'custom',
|
||||
};
|
||||
|
||||
const resolveData = {
|
||||
request: 'aModuleWeDontCareAbout',
|
||||
context: '/some/random/directory',
|
||||
};
|
||||
const resolveDataIn = Object.create(resolveData);
|
||||
|
||||
// Mocks
|
||||
const {
|
||||
compiler,
|
||||
normalModuleFactory_tap,
|
||||
normalModuleFactory_resolve_tap,
|
||||
} = createNMFResolveCompilerObject(resolveDataIn);
|
||||
|
||||
// Act
|
||||
const plugin = new FilerWebpackPlugin(options);
|
||||
plugin.apply(compiler);
|
||||
|
||||
// Assert
|
||||
expect(normalModuleFactory_tap.calls).to.have.length(1);
|
||||
expect(normalModuleFactory_tap.calls[0].args[0]).to.equal('filer-webpack-plugin');
|
||||
|
||||
expect(normalModuleFactory_resolve_tap.calls).to.have.length(1);
|
||||
expect(normalModuleFactory_resolve_tap.calls[0].args[0]).to.equal('filer-webpack-plugin');
|
||||
|
||||
expect(resolveDataIn.request).to.equal(resolveData.request);
|
||||
});
|
||||
|
||||
it('should resolve fsProvider to <fsProviderDir>/default.js when fsProvider options is default', () => {
|
||||
// Arrange
|
||||
const options = {
|
||||
filerDir: '/filer',
|
||||
shimsDir: '/shims',
|
||||
fsProviderDir: '/fsProvider',
|
||||
shimFs: false,
|
||||
shimPath: false,
|
||||
fsProvider: 'default',
|
||||
};
|
||||
|
||||
const resolveData = {
|
||||
request: 'fsProvider',
|
||||
context: options.shimsDir,
|
||||
};
|
||||
const resolveDataIn = Object.create(resolveData);
|
||||
|
||||
// Mocks
|
||||
const {
|
||||
compiler,
|
||||
normalModuleFactory_tap,
|
||||
normalModuleFactory_resolve_tap,
|
||||
} = createNMFResolveCompilerObject(resolveDataIn);
|
||||
|
||||
// Act
|
||||
const plugin = new FilerWebpackPlugin(options);
|
||||
plugin.apply(compiler);
|
||||
|
||||
// Assert
|
||||
expect(normalModuleFactory_tap.calls).to.have.length(1);
|
||||
expect(normalModuleFactory_tap.calls[0].args[0]).to.equal('filer-webpack-plugin');
|
||||
|
||||
expect(normalModuleFactory_resolve_tap.calls).to.have.length(1);
|
||||
expect(normalModuleFactory_resolve_tap.calls[0].args[0]).to.equal('filer-webpack-plugin');
|
||||
|
||||
expect(resolveDataIn.request).to.equal(`${options.fsProviderDir}/default.js`);
|
||||
});
|
||||
|
||||
it('should resolve fsProvider to <fsProviderDir>/indexeddb.js when fsProvider options is indexeddb', () => {
|
||||
// Arrange
|
||||
const options = {
|
||||
filerDir: '/filer',
|
||||
shimsDir: '/shims',
|
||||
fsProviderDir: '/fsProvider',
|
||||
shimFs: false,
|
||||
shimPath: false,
|
||||
fsProvider: 'indexeddb',
|
||||
};
|
||||
|
||||
const resolveData = {
|
||||
request: 'fsProvider',
|
||||
context: options.shimsDir,
|
||||
};
|
||||
const resolveDataIn = Object.create(resolveData);
|
||||
|
||||
// Mocks
|
||||
const {
|
||||
compiler,
|
||||
normalModuleFactory_tap,
|
||||
normalModuleFactory_resolve_tap,
|
||||
} = createNMFResolveCompilerObject(resolveDataIn);
|
||||
|
||||
// Act
|
||||
const plugin = new FilerWebpackPlugin(options);
|
||||
plugin.apply(compiler);
|
||||
|
||||
// Assert
|
||||
expect(normalModuleFactory_tap.calls).to.have.length(1);
|
||||
expect(normalModuleFactory_tap.calls[0].args[0]).to.equal('filer-webpack-plugin');
|
||||
|
||||
expect(normalModuleFactory_resolve_tap.calls).to.have.length(1);
|
||||
expect(normalModuleFactory_resolve_tap.calls[0].args[0]).to.equal('filer-webpack-plugin');
|
||||
|
||||
expect(resolveDataIn.request).to.equal(`${options.fsProviderDir}/indexeddb.js`);
|
||||
});
|
||||
|
||||
it('should resolve fsProvider to <fsProviderDir>/memory.js when fsProvider options is memory', () => {
|
||||
// Arrange
|
||||
const options = {
|
||||
filerDir: '/filer',
|
||||
shimsDir: '/shims',
|
||||
fsProviderDir: '/fsProvider',
|
||||
shimFs: false,
|
||||
shimPath: false,
|
||||
fsProvider: 'memory',
|
||||
};
|
||||
|
||||
const resolveData = {
|
||||
request: 'fsProvider',
|
||||
context: options.shimsDir,
|
||||
};
|
||||
const resolveDataIn = Object.create(resolveData);
|
||||
|
||||
// Mocks
|
||||
const {
|
||||
compiler,
|
||||
normalModuleFactory_tap,
|
||||
normalModuleFactory_resolve_tap,
|
||||
} = createNMFResolveCompilerObject(resolveDataIn);
|
||||
|
||||
// Act
|
||||
const plugin = new FilerWebpackPlugin(options);
|
||||
plugin.apply(compiler);
|
||||
|
||||
// Assert
|
||||
expect(normalModuleFactory_tap.calls).to.have.length(1);
|
||||
expect(normalModuleFactory_tap.calls[0].args[0]).to.equal('filer-webpack-plugin');
|
||||
|
||||
expect(normalModuleFactory_resolve_tap.calls).to.have.length(1);
|
||||
expect(normalModuleFactory_resolve_tap.calls[0].args[0]).to.equal('filer-webpack-plugin');
|
||||
|
||||
expect(resolveDataIn.request).to.equal(`${options.fsProviderDir}/memory.js`);
|
||||
});
|
||||
|
||||
it('should resolve fsProvider to <fsProviderDir>/custom.js when fsProvider options is custom', () => {
|
||||
// Arrange
|
||||
const options = {
|
||||
filerDir: '/filer',
|
||||
shimsDir: '/shims',
|
||||
fsProviderDir: '/fsProvider',
|
||||
shimFs: false,
|
||||
shimPath: false,
|
||||
fsProvider: 'custom',
|
||||
};
|
||||
|
||||
const resolveData = {
|
||||
request: 'fsProvider',
|
||||
context: options.shimsDir,
|
||||
};
|
||||
const resolveDataIn = Object.create(resolveData);
|
||||
|
||||
// Mocks
|
||||
const {
|
||||
compiler,
|
||||
normalModuleFactory_tap,
|
||||
normalModuleFactory_resolve_tap,
|
||||
} = createNMFResolveCompilerObject(resolveDataIn);
|
||||
|
||||
// Act
|
||||
const plugin = new FilerWebpackPlugin(options);
|
||||
plugin.apply(compiler);
|
||||
|
||||
// Assert
|
||||
expect(normalModuleFactory_tap.calls).to.have.length(1);
|
||||
expect(normalModuleFactory_tap.calls[0].args[0]).to.equal('filer-webpack-plugin');
|
||||
|
||||
expect(normalModuleFactory_resolve_tap.calls).to.have.length(1);
|
||||
expect(normalModuleFactory_resolve_tap.calls[0].args[0]).to.equal('filer-webpack-plugin');
|
||||
|
||||
expect(resolveDataIn.request).to.equal(`${options.fsProviderDir}/custom.js`);
|
||||
});
|
||||
|
||||
it('should throw an error when an invalid options is provided for fsProvider', () => {
|
||||
// Arrange
|
||||
const options = {
|
||||
filerDir: '/filer',
|
||||
shimsDir: '/shims',
|
||||
fsProviderDir: '/fsProvider',
|
||||
shimFs: false,
|
||||
shimPath: false,
|
||||
fsProvider: 'invalid_fs_provider_option',
|
||||
};
|
||||
|
||||
const resolveData = {
|
||||
request: 'fsProvider',
|
||||
context: options.shimsDir,
|
||||
};
|
||||
const resolveDataIn = Object.create(resolveData);
|
||||
|
||||
// Mocks
|
||||
const {
|
||||
compiler,
|
||||
} = createNMFResolveCompilerObject(resolveDataIn);
|
||||
|
||||
// Act
|
||||
const plugin = new FilerWebpackPlugin(options);
|
||||
|
||||
// Act // Assert
|
||||
expect(() => {
|
||||
plugin.apply(compiler);
|
||||
}).to.throw();
|
||||
});
|
||||
|
||||
it('should ignore a request for fs when the context is in the filer directory', () => {
|
||||
// Arrange
|
||||
const options = {
|
||||
filerDir: '/filer',
|
||||
shimsDir: '/shims',
|
||||
fsProviderDir: '/fsProvider',
|
||||
shimFs: false,
|
||||
shimPath: false,
|
||||
fsProvider: 'custom',
|
||||
};
|
||||
|
||||
const resolveData = {
|
||||
request: 'fs',
|
||||
context: options.filerDir + '/src',
|
||||
};
|
||||
const resolveDataIn = Object.create(resolveData);
|
||||
|
||||
// Mocks
|
||||
const {
|
||||
compiler,
|
||||
normalModuleFactory_tap,
|
||||
normalModuleFactory_resolve_tap,
|
||||
} = createNMFResolveCompilerObject(resolveDataIn);
|
||||
|
||||
// Act
|
||||
const plugin = new FilerWebpackPlugin(options);
|
||||
plugin.apply(compiler);
|
||||
|
||||
// Assert
|
||||
expect(normalModuleFactory_tap.calls).to.have.length(1);
|
||||
expect(normalModuleFactory_tap.calls[0].args[0]).to.equal('filer-webpack-plugin');
|
||||
|
||||
expect(normalModuleFactory_resolve_tap.calls).to.have.length(1);
|
||||
expect(normalModuleFactory_resolve_tap.calls[0].args[0]).to.equal('filer-webpack-plugin');
|
||||
|
||||
expect(resolveDataIn.request).to.equal(resolveData.request);
|
||||
});
|
||||
|
||||
it('should resolve a request for fs to the fs shim when the context is not in the filer directory', () => {
|
||||
// Arrange
|
||||
const options = {
|
||||
filerDir: '/filer',
|
||||
shimsDir: '/shims',
|
||||
fsProviderDir: '/fsProvider',
|
||||
shimFs: true,
|
||||
shimPath: true,
|
||||
fsProvider: 'custom',
|
||||
};
|
||||
|
||||
const resolveData = {
|
||||
request: 'fs',
|
||||
context: '/some/random/directory',
|
||||
};
|
||||
const resolveDataIn = Object.create(resolveData);
|
||||
|
||||
// Mocks
|
||||
const {
|
||||
compiler,
|
||||
normalModuleFactory_tap,
|
||||
normalModuleFactory_resolve_tap,
|
||||
} = createNMFResolveCompilerObject(resolveDataIn);
|
||||
|
||||
// Act
|
||||
const plugin = new FilerWebpackPlugin(options);
|
||||
plugin.apply(compiler);
|
||||
|
||||
// Assert
|
||||
expect(normalModuleFactory_tap.calls).to.have.length(1);
|
||||
expect(normalModuleFactory_tap.calls[0].args[0]).to.equal('filer-webpack-plugin');
|
||||
|
||||
expect(normalModuleFactory_resolve_tap.calls).to.have.length(1);
|
||||
expect(normalModuleFactory_resolve_tap.calls[0].args[0]).to.equal('filer-webpack-plugin');
|
||||
|
||||
expect(resolveDataIn.request).to.equal(`${options.shimsDir}/fs.js`);
|
||||
});
|
||||
|
||||
it('should not resolve a request for fs to the fs shim when the context is not in the filer directory but shimFs is false', () => {
|
||||
// Arrange
|
||||
const options = {
|
||||
filerDir: '/filer',
|
||||
shimsDir: '/shims',
|
||||
fsProviderDir: '/fsProvider',
|
||||
shimFs: false,
|
||||
shimPath: false,
|
||||
fsProvider: 'custom',
|
||||
};
|
||||
|
||||
const resolveData = {
|
||||
request: 'fs',
|
||||
context: '/some/random/directory',
|
||||
};
|
||||
const resolveDataIn = Object.create(resolveData);
|
||||
|
||||
// Mocks
|
||||
const {
|
||||
compiler,
|
||||
normalModuleFactory_tap,
|
||||
normalModuleFactory_resolve_tap,
|
||||
} = createNMFResolveCompilerObject(resolveDataIn);
|
||||
|
||||
// Act
|
||||
const plugin = new FilerWebpackPlugin(options);
|
||||
plugin.apply(compiler);
|
||||
|
||||
// Assert
|
||||
expect(normalModuleFactory_tap.calls).to.have.length(1);
|
||||
expect(normalModuleFactory_tap.calls[0].args[0]).to.equal('filer-webpack-plugin');
|
||||
|
||||
expect(normalModuleFactory_resolve_tap.calls).to.have.length(1);
|
||||
expect(normalModuleFactory_resolve_tap.calls[0].args[0]).to.equal('filer-webpack-plugin');
|
||||
|
||||
expect(resolveDataIn.request).to.equal(resolveData.request);
|
||||
});
|
||||
|
||||
it('should resolve a request for path to the path shim when the context is not in the filer directory', () => {
|
||||
// Arrange
|
||||
const options = {
|
||||
filerDir: '/filer',
|
||||
shimsDir: '/shims',
|
||||
fsProviderDir: '/fsProvider',
|
||||
shimFs: true,
|
||||
shimPath: true,
|
||||
fsProvider: 'custom',
|
||||
};
|
||||
|
||||
const resolveData = {
|
||||
request: 'path',
|
||||
context: '/some/random/directory',
|
||||
};
|
||||
const resolveDataIn = Object.create(resolveData);
|
||||
|
||||
// Mocks
|
||||
const {
|
||||
compiler,
|
||||
normalModuleFactory_tap,
|
||||
normalModuleFactory_resolve_tap,
|
||||
} = createNMFResolveCompilerObject(resolveDataIn);
|
||||
|
||||
// Act
|
||||
const plugin = new FilerWebpackPlugin(options);
|
||||
plugin.apply(compiler);
|
||||
|
||||
// Assert
|
||||
expect(normalModuleFactory_tap.calls).to.have.length(1);
|
||||
expect(normalModuleFactory_tap.calls[0].args[0]).to.equal('filer-webpack-plugin');
|
||||
|
||||
expect(normalModuleFactory_resolve_tap.calls).to.have.length(1);
|
||||
expect(normalModuleFactory_resolve_tap.calls[0].args[0]).to.equal('filer-webpack-plugin');
|
||||
|
||||
expect(resolveDataIn.request).to.equal(`${options.shimsDir}/path.js`);
|
||||
});
|
||||
|
||||
it('should not resolve a request for path to the path shim when the context is not in the filer directory but shimPath is false', () => {
|
||||
// Arrange
|
||||
const options = {
|
||||
filerDir: '/filer',
|
||||
shimsDir: '/shims',
|
||||
fsProviderDir: '/fsProvider',
|
||||
shimFs: false,
|
||||
shimPath: false,
|
||||
fsProvider: 'custom',
|
||||
};
|
||||
|
||||
const resolveData = {
|
||||
request: 'path',
|
||||
context: '/some/random/directory',
|
||||
};
|
||||
const resolveDataIn = Object.create(resolveData);
|
||||
|
||||
// Mocks
|
||||
const {
|
||||
compiler,
|
||||
normalModuleFactory_tap,
|
||||
normalModuleFactory_resolve_tap,
|
||||
} = createNMFResolveCompilerObject(resolveDataIn);
|
||||
|
||||
// Act
|
||||
const plugin = new FilerWebpackPlugin(options);
|
||||
plugin.apply(compiler);
|
||||
|
||||
// Assert
|
||||
expect(normalModuleFactory_tap.calls).to.have.length(1);
|
||||
expect(normalModuleFactory_tap.calls[0].args[0]).to.equal('filer-webpack-plugin');
|
||||
|
||||
expect(normalModuleFactory_resolve_tap.calls).to.have.length(1);
|
||||
expect(normalModuleFactory_resolve_tap.calls[0].args[0]).to.equal('filer-webpack-plugin');
|
||||
|
||||
expect(resolveDataIn.request).to.equal(resolveData.request);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
FilerWebpackPlugin: require('../src/webpack-plugin'),
|
||||
};
|
Loading…
Reference in New Issue