Skip to content

Commit

Permalink
fs, feat: add test for 'require' when calling zip.open. (#448)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardo2016 authored and xicilion committed Jul 31, 2018
1 parent 4a18563 commit 66f5f8d
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions test/fs_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var isWin32 = process.platform === 'win32';
function unlink(pathname) {
try {
fs.rmdir(pathname);
} catch (e) {}
} catch (e) { }
}

var pathname = 'test_dir' + vmid;
Expand All @@ -31,7 +31,7 @@ describe('fs', () => {
after(() => {
try {
fs.unlink(path.join(__dirname, 'unzip_test.zip'));
} catch (e) {}
} catch (e) { }
});

it("stat", () => {
Expand Down Expand Up @@ -329,23 +329,27 @@ describe('fs', () => {
function save_zip(n) {
var zipfile = zip.open(path.join(__dirname, 'unzip_test.zip'), "w");
zipfile.write(new Buffer('test ' + n), 'test.txt');
zipfile.write(new Buffer(`module.exports = "fibjs-test-require-${n}"`), 'test.js');
zipfile.close();
}

function test_zip(n) {
function test_zip(n, first_test_n = n) {
assert.equal(fs.readTextFile(path.join(__dirname, "unzip_test.zip$", "test.txt")),
"test " + n);
assert.equal(require('./unzip_test.zip$/test.js'), `fibjs-test-require-${first_test_n}`)
}

save_zip(1);
var first_test_n = 1;

save_zip(first_test_n);
coroutine.sleep(1000);
test_zip(1);
test_zip(first_test_n);

save_zip(2);
test_zip(1);
test_zip(1, first_test_n);

coroutine.sleep(4000);
test_zip(2);
test_zip(2, first_test_n);
});

it("zip data", () => {
Expand Down

0 comments on commit 66f5f8d

Please sign in to comment.