Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VFS Archive support #67

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf

[test.txt]
[exampleFileWithContents.txt]
insert_final_newline = false
120 changes: 104 additions & 16 deletions __tests__/adapters/vfs/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,27 +168,115 @@ describe('VFS System adapter', () => {
);
});

test('#unlink', () => {
const files = ['home:/test', 'home:/test-directory', 'home:/test-rename'];

return Promise.all(files.map(f => {
return expect(request('unlink', f, createOptions()))
.resolves
.toBe(true);
}));
});

test('#unlink', () => {
return expect(request('unlink', 'home:/test-directory', createOptions()))
.resolves
.toBe(true);
});

test('#realpath', () => {
const realPath = path.join(core.configuration.tempPath, 'jest/test');

return expect(request('realpath', 'home:/test', createOptions()))
.resolves
.toBe(realPath);
});

test('#archive - compress files', async () => {
const options = createOptions({action: 'compress'});

// Compress the files
await expect(
request('archive', ['home:/test', 'home:/test-rename'], options)
).resolves.toBe(true);

// Ensure the zip file exists
await expect(
request('exists', 'home:/test.zip', createOptions())
).resolves.toBe(true);
});

test('#archive - compress directory', async () => {
const options = createOptions({action: 'compress'});

// Compress the directory
await expect(
request('archive', ['home:/test-directory'], options)
).resolves.toBe(true);

// Ensure the zip file exists
await expect(
request('exists', 'home:/test-directory.zip', createOptions())
).resolves.toBe(true);
});

test('#archive - compress error', () => {
const options = createOptions({action: 'compress'});

return expect(
request('archive', ['home:/fakefile.php'], options)
).rejects.toThrowError();
});

test('#archive - extract', async () => {
const options = createOptions({action: 'extract'});

// Extract the archive
await expect(
request('archive', ['home:/test.zip'], options)
).resolves.toBe(true);

// Ensure a folder was created for the extracted files
await expect(
request('exists', 'home:/test', createOptions())
).resolves.toBe(true);

// Check the contents of the directory
const extractedFiles = await request('readdir', 'home:/test', createOptions());
expect(extractedFiles).toEqual(
expect.arrayContaining([
expect.objectContaining({filename: 'test', isFile: true}),
expect.objectContaining({filename: 'test-rename', isFile: true}),
])
);

// Ensure the contents of the files are the same
const extractedFileContents = await fs.readFile(path.join(core.config('tempPath'), 'jest/test/test'), 'utf8');
expect(extractedFileContents).toBe('jest');

const extractedEmptyFileContents = await fs.readFile(path.join(core.config('tempPath'), 'jest/test/test-rename'), 'utf8');
expect(extractedEmptyFileContents).toBe('');
});

test('#archive - extract error', () => {
const options = createOptions({action: 'extract'});

return expect(
request('archive', ['home:/fakefile.php'], options)
).rejects.toThrowError();
});

test('#archive - bad option', () => {
const options = createOptions({action: 'fake'});

return expect(
request('archive', ['home:/text.txt.zip'], options)
).rejects.toThrowError();
});

test('#unlink - files', () => {
const files = ['home:/test.zip', 'home:/test/test', 'home:/test/test-rename'];

return Promise.all(
files.map((file) => {
return expect(request('unlink', file, createOptions())).resolves.toBe(
true
);
})
);
});

test('#unlink - folders', () => {
const directories = ['home:/test-directory', 'home:/test'];

return Promise.all(
directories.map((dir) => {
return expect(request('unlink', dir, createOptions())).resolves.toBe(true);
})
);
});
});
4 changes: 2 additions & 2 deletions __tests__/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ describe('Authentication', () => {
await auth.login(request, response);

request.fields = {
path: 'home:/otherfile.xml'
path: 'home:/exampleEmptyFile.xml'
};
const fileExists = await filesystem.request('exists', request);
expect(fileExists).toBe(true);

request.fields = {
path: 'home:/test.txt'
path: 'home:/exampleFileWithContents.txt'
};

let chunks = [];
Expand Down
Loading