Initial version
This commit is contained in:
21
tests/.babelrc
Normal file
21
tests/.babelrc
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"presets": [
|
||||
[
|
||||
"@babel/preset-env",
|
||||
{
|
||||
"targets": {
|
||||
"node": "current"
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
"plugins": [
|
||||
[ "@babel/plugin-proposal-decorators" , { "legacy": true }],
|
||||
[ "@babel/plugin-proposal-class-properties", { "loose": true } ],
|
||||
[ "@babel/plugin-proposal-private-methods", {"loose": true } ],
|
||||
[ "@babel/plugin-proposal-optional-chaining" ],
|
||||
[ "@babel/plugin-proposal-nullish-coalescing-operator" ],
|
||||
[ "@babel/plugin-proposal-export-namespace-from" ],
|
||||
[ "@babel/plugin-proposal-export-default-from" ]
|
||||
]
|
||||
}
|
||||
1
tests/host/basic/dist/other/another-file.txt
vendored
Normal file
1
tests/host/basic/dist/other/another-file.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
I serve to fill a tree of files
|
||||
1
tests/host/basic/dist/other/more-files.out
vendored
Normal file
1
tests/host/basic/dist/other/more-files.out
vendored
Normal file
@@ -0,0 +1 @@
|
||||
I also serve to fill a tree of files!
|
||||
1
tests/host/basic/dist/test-file.txt
vendored
Normal file
1
tests/host/basic/dist/test-file.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
I am a very basic test-file yo!
|
||||
1
tests/host/basic/test-file.out
Normal file
1
tests/host/basic/test-file.out
Normal file
@@ -0,0 +1 @@
|
||||
I am the first basic test-file!
|
||||
33
tests/host/host.basic.test.js
Normal file
33
tests/host/host.basic.test.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import {Host} from "../../dist";
|
||||
import {resolve} from "path";
|
||||
|
||||
test('host.basic', async ()=>{
|
||||
let host = new Host({workingDirectory: __dirname});
|
||||
|
||||
await host.remove("basic", {recursive: true});// Make sure dir is removed and we have clean start (could have the user pass a force flag here..
|
||||
let testHost = await host.cwd('basic');
|
||||
|
||||
await testHost.write('test-file.out', "I am the first basic test-file!");
|
||||
await testHost.write('dist/test-file.txt', "I am a very basic test-file yo!");
|
||||
await testHost.write('dist/other/another-file.txt', "I serve to fill a tree of files");
|
||||
await testHost.write('dist/other/more-files.out', "I also serve to fill a tree of files!");
|
||||
|
||||
let tree = await testHost.traverse();
|
||||
expect(tree.length).toBe(6); // Expecting 6 results, because it should include the directories as well
|
||||
|
||||
let txtFiles = await testHost.glob('**/*.txt');
|
||||
expect(txtFiles.length).toBe(2);
|
||||
|
||||
let outFiles = await testHost.glob('**/*.out');
|
||||
expect(outFiles.length).toBe(2);
|
||||
|
||||
|
||||
let subHost = testHost.from('dist/other');
|
||||
let subOutFiles = await subHost.glob('../../**/*.out');
|
||||
expect(subOutFiles.length).toBe(2);
|
||||
|
||||
|
||||
/** @type {module:fs.Stats} */
|
||||
let stats = await host.stat('basic/test-file.out');
|
||||
expect(stats.isFile()).toBe(true);
|
||||
});
|
||||
12
tests/host/host.relative.test.js
Normal file
12
tests/host/host.relative.test.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import {Host} from "../../dist";
|
||||
|
||||
test('host.basic', async ()=>{
|
||||
let host = new Host({workingDirectory: __dirname});
|
||||
let distHost = host.from("dist");
|
||||
|
||||
let relMain = distHost.relative(host.resolve("dist/main.js"));
|
||||
expect(relMain).toBe('main.js');
|
||||
|
||||
let relAsset = distHost.relative(host.resolve("dist/assets/icon.svg"));
|
||||
expect(relAsset).toBe('assets/icon.svg');
|
||||
});
|
||||
1
tests/host/test/dist/other/another-file.txt
vendored
Normal file
1
tests/host/test/dist/other/another-file.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
I serve to fill a tree of files
|
||||
1
tests/host/test/dist/other/more-files.out
vendored
Normal file
1
tests/host/test/dist/other/more-files.out
vendored
Normal file
@@ -0,0 +1 @@
|
||||
I also serve to fill a tree of files!
|
||||
1
tests/host/test/dist/test-file.txt
vendored
Normal file
1
tests/host/test/dist/test-file.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
I am a very basic test-file yo!
|
||||
1
tests/host/test/test-file.out
Normal file
1
tests/host/test/test-file.out
Normal file
@@ -0,0 +1 @@
|
||||
I am the first basic test-file!
|
||||
1
tests/manual/dist/assets/icon2.svg
vendored
Normal file
1
tests/manual/dist/assets/icon2.svg
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<svg>I'm an new example icon</svg>
|
||||
|
After Width: | Height: | Size: 34 B |
1
tests/manual/dist/assets/logo.png
vendored
Normal file
1
tests/manual/dist/assets/logo.png
vendored
Normal file
@@ -0,0 +1 @@
|
||||
I'm to lazy to make a miniature example image'
|
||||
1
tests/manual/dist/index.html
vendored
Normal file
1
tests/manual/dist/index.html
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<html><body>I am no longer the same entry-html file!</body></html>
|
||||
5
tests/manual/process-args-dummy.js
Normal file
5
tests/manual/process-args-dummy.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import {processArgs} from "../../dist";
|
||||
let rawArgs = process.argv;
|
||||
|
||||
console.log(`Raw: ${JSON.stringify(rawArgs)}`);
|
||||
console.log(`Processed: ${JSON.stringify(processArgs)}`);
|
||||
16
tests/manual/process-args.js
Normal file
16
tests/manual/process-args.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import {host, Host} from "../../dist";
|
||||
|
||||
/** @type {Host} **/// Would really wish we can eliminate the need for this...
|
||||
const local = host.from(__dirname);
|
||||
|
||||
let dummyScript = `process-args-dummy`;
|
||||
|
||||
let testCommands = [
|
||||
`-xfv arg1 var1="some option value"`
|
||||
];
|
||||
|
||||
for(let testCmd of testCommands){
|
||||
let cmd = `node -r @babel/register ${dummyScript} ${testCmd}`;
|
||||
console.log(`Test: ${cmd}`);
|
||||
local.exec(cmd);
|
||||
}
|
||||
1
tests/manual/src/.babelrc
Normal file
1
tests/manual/src/.babelrc
Normal file
@@ -0,0 +1 @@
|
||||
//I represent another source-file whose edit shouldn't have been seen!
|
||||
1
tests/manual/src/assets/icon2.svg
Normal file
1
tests/manual/src/assets/icon2.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg>I'm an new example icon</svg>
|
||||
|
After Width: | Height: | Size: 34 B |
1
tests/manual/src/assets/logo.png
Normal file
1
tests/manual/src/assets/logo.png
Normal file
@@ -0,0 +1 @@
|
||||
I'm to lazy to make a miniature example image'
|
||||
1
tests/manual/src/common/another-source-file.js
Normal file
1
tests/manual/src/common/another-source-file.js
Normal file
@@ -0,0 +1 @@
|
||||
//I represent a service or common part of sorts
|
||||
1
tests/manual/src/index.html
Normal file
1
tests/manual/src/index.html
Normal file
@@ -0,0 +1 @@
|
||||
<html><body>I am no longer the same entry-html file!</body></html>
|
||||
1
tests/manual/src/main.js
Normal file
1
tests/manual/src/main.js
Normal file
@@ -0,0 +1 @@
|
||||
//I represent a main-file
|
||||
1
tests/manual/test/dist/other/another-file.txt
vendored
Normal file
1
tests/manual/test/dist/other/another-file.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
I am no longer the same file i used to be!
|
||||
1
tests/manual/test/dist/other/more-files.out
vendored
Normal file
1
tests/manual/test/dist/other/more-files.out
vendored
Normal file
@@ -0,0 +1 @@
|
||||
I also serve to fill a tree of files!
|
||||
1
tests/manual/test/dist/test-file2.txt
vendored
Normal file
1
tests/manual/test/dist/test-file2.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
I am a new test-file!
|
||||
1
tests/manual/test/dist2/test-file.txt
Normal file
1
tests/manual/test/dist2/test-file.txt
Normal file
@@ -0,0 +1 @@
|
||||
I am a new test-file!
|
||||
1
tests/manual/test/test-file.out
Normal file
1
tests/manual/test/test-file.out
Normal file
@@ -0,0 +1 @@
|
||||
I am the first basic test-file!
|
||||
62
tests/manual/watch-glob.dev.js
Normal file
62
tests/manual/watch-glob.dev.js
Normal file
@@ -0,0 +1,62 @@
|
||||
import {Host} from "../../dist";
|
||||
|
||||
async function testWatch(){
|
||||
let host = new Host({workingDirectory: __dirname});
|
||||
|
||||
await host.remove("test", {recursive: true});// Make sure dir is removed and we have clean start (could have the user pass a force flag here..
|
||||
|
||||
let initialized = false;
|
||||
let testHost = await host.cwd('test');
|
||||
|
||||
await testHost.write('test-file.out', "I am the first basic test-file!");
|
||||
await testHost.write('dist/test-file.txt', "I am a very basic test-file yo!");
|
||||
await testHost.write('dist/other/another-file.txt', "I serve to fill a tree of files");
|
||||
await testHost.write('dist/other/more-files.out', "I also serve to fill a tree of files!");
|
||||
initialized = true;
|
||||
|
||||
// TODO starting a watch on a dir before it is created does not work yet!!
|
||||
let watchSub = host.watch("test").glob("**/*.txt").subscribe(({changes, files})=>{
|
||||
console.log(`----------\nChanges:\n${
|
||||
changes.map(x=>x.event.toUpperCase() + ": " + x.file).join('\n')
|
||||
}\nFiles:\n${files.join("\n")}\n----------`);
|
||||
});
|
||||
|
||||
await new Promise((resolve,reject)=>setTimeout(()=>resolve(),1000));
|
||||
|
||||
// Watch a remove having occurred
|
||||
console.log("\n** Removing dist/test-file.txt");
|
||||
await testHost.remove('dist/test-file.txt');
|
||||
console.log("** Removed dist/test-file.txt\n");
|
||||
|
||||
await new Promise((resolve,reject)=>setTimeout(()=>resolve(),1000));
|
||||
|
||||
// Watch an add having occurred
|
||||
console.log("\n** Adding dist/test-file2.txt");
|
||||
await testHost.write('dist/test-file2.txt', 'I am a new test-file!');
|
||||
console.log("** Added dist/test-file2.txt\n");
|
||||
|
||||
await new Promise((resolve,reject)=>setTimeout(()=>resolve(),1000));
|
||||
|
||||
// Watch a copy having occurred
|
||||
console.log("\n** Copying dist/test-file2.txt to dist2/test-file.txt");
|
||||
await testHost.copy('dist/test-file2.txt', "dist2/test-file.txt");
|
||||
console.log("** Copied dist2/test-file.txt\n");
|
||||
|
||||
await new Promise((resolve,reject)=>setTimeout(()=>resolve(), 1000));// clearly our current process is slow
|
||||
|
||||
// Watch an edit having occurred
|
||||
console.log("\n** Writing dist/other/another-file.txt");
|
||||
await testHost.write('dist/other/another-file.txt', 'I am no longer the same file i used to be!');
|
||||
console.log("** Written dist/other/another-file.txt\n");
|
||||
|
||||
await new Promise((resolve,reject)=>setTimeout(()=>resolve(), 3000));// clearly our current process is slow
|
||||
|
||||
console.log("UNSUBSCRIBING!");
|
||||
|
||||
// No longer watching should close all file handles!
|
||||
watchSub.unsubscribe();
|
||||
|
||||
console.log("DONE!");
|
||||
}
|
||||
|
||||
testWatch();
|
||||
74
tests/manual/watch-sync.dev.js
Normal file
74
tests/manual/watch-sync.dev.js
Normal file
@@ -0,0 +1,74 @@
|
||||
import {Host} from "../../dist";
|
||||
|
||||
async function testWatch(){
|
||||
let host = new Host({workingDirectory: __dirname});
|
||||
let initialized = false;
|
||||
|
||||
// Initialize
|
||||
await host.remove("src", {recursive: true});// Make sure dir is removed and we have clean start (could have the user pass a force flag here..
|
||||
await host.remove("dist", {recursive: true});// Make sure dir is removed and we have clean start (could have the user pass a force flag here..
|
||||
let srcHost = await host.cwd('src');
|
||||
await srcHost.write('main.js', "//I represent a main-file");
|
||||
await srcHost.write('assets/icon.svg', "<svg>I'm an example icon</svg>");
|
||||
await srcHost.write('assets/logo.png', "I'm to lazy to make a miniature example image'");
|
||||
await srcHost.write('common/another-source-file.js', "//I represent a service or common part of sorts");
|
||||
await srcHost.write('.babelrc', "//I represent another source-file to be excluded from being copied");
|
||||
await srcHost.write('index.html', "<html><body>I represent the entry-html file!</body></html>");
|
||||
initialized = true;
|
||||
|
||||
console.log("Initialized, starting sync");
|
||||
|
||||
// Syntax like this for the moment! (this might change in the future...)
|
||||
let syncSub = host.watch("src").glob("**/*.!(js|babelrc|json|scss)").sync("dist").subscribe(sync=>{
|
||||
let changes = sync.changes;
|
||||
console.log(`----------\nSYNCED Changes:\n${
|
||||
changes.map(x=>x.event.toUpperCase() + ": " + x.file).join('\n')
|
||||
}\n`);
|
||||
});
|
||||
|
||||
let watchSub = host.watch("src").glob("**/*.!(js|babelrc|json|scss)").subscribe((event)=>{
|
||||
let {changes, files} = event;
|
||||
console.log(`----------\nOBSERVED Changes:\n${
|
||||
changes.map(x=>x.event.toUpperCase() + ": " + x.file).join('\n')
|
||||
}\nFiles:\n${files.join("\n")}\n----------`);
|
||||
});
|
||||
|
||||
await new Promise((resolve,reject)=>setTimeout(()=>resolve(),1000));
|
||||
|
||||
// Watch a remove having occurred
|
||||
console.log("** Removing assets/icon.svg");
|
||||
await srcHost.remove('assets/icon.svg');
|
||||
console.log("** Removed assets/icon.svg\n");
|
||||
|
||||
await new Promise((resolve,reject)=>setTimeout(()=>resolve(),1000));
|
||||
|
||||
// Watch an add having occurred
|
||||
console.log("** Adding assets/icon2.svg");
|
||||
await srcHost.write('assets/icon2.svg', "<svg>I'm an new example icon</svg>");
|
||||
console.log("** Added assets/icon2.svg\n");
|
||||
|
||||
await new Promise((resolve,reject)=>setTimeout(()=>resolve(),1000));
|
||||
|
||||
// Watch an edit having occurred
|
||||
console.log("** Writing index.html");
|
||||
await srcHost.write('index.html', "<html><body>I am no longer the same entry-html file!</body></html>");
|
||||
console.log("** Written index.html\n");
|
||||
|
||||
await new Promise((resolve,reject)=>setTimeout(()=>resolve(), 1000));// clearly our current process is slow
|
||||
|
||||
// Test an unwatched edit having occurred
|
||||
console.log("** Writing .babelrc");
|
||||
await srcHost.write('.babelrc', "//I represent another source-file whose edit shouldn't have been seen!");
|
||||
console.log("** Written babelrc\n");
|
||||
|
||||
await new Promise((resolve,reject)=>setTimeout(()=>resolve(), 3000));// clearly our current process is slow
|
||||
|
||||
console.log("UNSUBSCRIBING!");
|
||||
|
||||
// No longer watching should close all file handles!
|
||||
watchSub.unsubscribe();
|
||||
syncSub.unsubscribe();
|
||||
console.log("DONE!");
|
||||
}
|
||||
|
||||
testWatch();
|
||||
58
tests/manual/watch.dev.js
Normal file
58
tests/manual/watch.dev.js
Normal file
@@ -0,0 +1,58 @@
|
||||
import {Host} from "../../dist";
|
||||
|
||||
async function testWatch(){
|
||||
let host = new Host({workingDirectory: __dirname});
|
||||
|
||||
await host.remove("test", {recursive: true});// Make sure dir is removed and we have clean start (could have the user pass a force flag here..
|
||||
|
||||
let initialized = false;
|
||||
let testHost = await host.cwd('test');
|
||||
|
||||
await testHost.write('test-file.out', "I am the first basic test-file!");
|
||||
await testHost.write('dist/test-file.txt', "I am a very basic test-file yo!");
|
||||
await testHost.write('dist/other/another-file.txt', "I serve to fill a tree of files");
|
||||
await testHost.write('dist/other/more-files.out', "I also serve to fill a tree of files!");
|
||||
initialized = true;
|
||||
|
||||
// TODO starting a watch on a dir before it is created does not work yet!!
|
||||
let watchSub = host.watch("test").subscribe(({changes, files})=>{
|
||||
console.log(`----------\nChanges:\n${
|
||||
changes.map(x=>x.event.toUpperCase() + ": " + x.file).join('\n')
|
||||
}\nFiles:\n${files.join("\n")}\n----------`);
|
||||
});
|
||||
|
||||
await new Promise((resolve,reject)=>setTimeout(()=>resolve(),1000));// clearly our current process is slow
|
||||
|
||||
// Watch a remove having occurred
|
||||
console.log("** Removing dist/test-file.txt");
|
||||
await testHost.remove('dist/test-file.txt');
|
||||
console.log("** Removed dist/test-file.txt\n");
|
||||
|
||||
await new Promise((resolve,reject)=>setTimeout(()=>resolve(),1000));// clearly our current process is slow
|
||||
|
||||
// Watch an add having occurred
|
||||
console.log("** Adding dist/test-file2.txt");
|
||||
await testHost.write('dist/test-file2.txt', 'I am a new test-file!');
|
||||
console.log("** Added dist/test-file2.txt\n");
|
||||
|
||||
await new Promise((resolve,reject)=>setTimeout(()=>resolve(),1000));// clearly our current process is slow
|
||||
|
||||
// Watch a move having occurred TODO we don't have this feature yet!
|
||||
//await testHost.move('dist/test-file2.txt', 'dist2/test-file.txt');
|
||||
|
||||
// Watch an edit having occurred
|
||||
console.log("** Writing dist/other/another-file.txt");
|
||||
await testHost.write('dist/other/another-file.txt', 'I am no longer the same file i used to be!');
|
||||
console.log("** Written dist/other/another-file.txt\n");
|
||||
|
||||
await new Promise((resolve,reject)=>setTimeout(()=>resolve(), 3000));// clearly our current process is slow
|
||||
|
||||
console.log("UNSUBSCRIBING!");
|
||||
|
||||
// No longer watching should close all file handles!
|
||||
watchSub.unsubscribe();
|
||||
|
||||
console.log("DONE!");
|
||||
}
|
||||
|
||||
testWatch();
|
||||
Reference in New Issue
Block a user