|
1 | 1 | const {test} = require("ava");
|
2 | 2 | const {resourceFactory} = require("../../../");
|
3 | 3 |
|
| 4 | +async function fillFromFs(readerWriter) { |
| 5 | + const fsReader = resourceFactory.createAdapter({ |
| 6 | + fsBasePath: "./test/fixtures/glob", |
| 7 | + virBasePath: "/app/", |
| 8 | + }); |
| 9 | + |
| 10 | + const fsResources = await fsReader.byGlob("/**/*"); |
| 11 | + return Promise.all(fsResources.map(function(resource) { |
| 12 | + return readerWriter.write(resource); |
| 13 | + })); |
| 14 | +} |
| 15 | + |
| 16 | +function matchGlobResult(t, resources, expectedResources) { |
| 17 | + t.deepEqual(resources.length, expectedResources.length, "Amount of files matches expected result."); |
| 18 | + |
| 19 | + const matchedResources = resources.map((resource) => { |
| 20 | + return resource.getPath(); |
| 21 | + }); |
| 22 | + |
| 23 | + for (let i = 0; i < expectedResources.length; i++) { |
| 24 | + const expectedResource = expectedResources[i]; |
| 25 | + t.true( |
| 26 | + matchedResources.indexOf(expectedResource) !== -1, |
| 27 | + "File '" + expectedResource + "' was found." |
| 28 | + ); |
| 29 | + } |
| 30 | +} |
| 31 | + |
4 | 32 | test("GLOB resources from application.a w/ virtual base path prefix", async (t) => {
|
5 | 33 | const readerWriter = resourceFactory.createAdapter({
|
6 | 34 | virBasePath: "/app/"
|
@@ -69,35 +97,7 @@ test("GLOB virtual directory w/ virtual base path prefix and nodir: true", async
|
69 | 97 | t.deepEqual(resources.length, 0, "Found no resources");
|
70 | 98 | });
|
71 | 99 |
|
72 |
| -// Load more data from FS into memory |
73 |
| -async function fillFromFs(readerWriter) { |
74 |
| - const fsReader = resourceFactory.createAdapter({ |
75 |
| - fsBasePath: "./test/fixtures/glob", |
76 |
| - virBasePath: "/app/", |
77 |
| - }); |
78 |
| - |
79 |
| - const fsResources = await fsReader.byGlob("/**/*"); |
80 |
| - return Promise.all(fsResources.map(function(resource) { |
81 |
| - return readerWriter.write(resource); |
82 |
| - })); |
83 |
| -} |
84 |
| - |
85 |
| -function matchGlobResult(t, resources, expectedResources) { |
86 |
| - t.deepEqual(resources.length, expectedResources.length, "Amount of files matches expected result."); |
87 |
| - |
88 |
| - const matchedResources = resources.map((resource) => { |
89 |
| - return resource.getPath(); |
90 |
| - }); |
91 |
| - |
92 |
| - for (let i = 0; i < expectedResources.length; i++) { |
93 |
| - const expectedResource = expectedResources[i]; |
94 |
| - t.true( |
95 |
| - matchedResources.indexOf(expectedResource) !== -1, |
96 |
| - "File '" + expectedResource + "' was found." |
97 |
| - ); |
98 |
| - } |
99 |
| -} |
100 |
| - |
| 100 | +/* Load more data from FS into memory */ |
101 | 101 | test("GLOB all", async (t) => {
|
102 | 102 | const readerWriter = resourceFactory.createAdapter({
|
103 | 103 | virBasePath: "/app/"
|
|
0 commit comments