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

Updates build filesystem unit tests to be Windows Compatible #24296

Merged
merged 1 commit into from
Oct 20, 2018
Merged
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
10 changes: 7 additions & 3 deletions src/dev/build/lib/__tests__/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const FOO_TAR_PATH = resolve(FIXTURES, 'foo_dir.tar.gz');
const BAR_TXT_PATH = resolve(FIXTURES, 'foo_dir/bar.txt');
const WORLD_EXECUTABLE = resolve(FIXTURES, 'bin/world_executable');

const isWindows = /^win/.test(process.platform);

// get the mode of a file as a string, like 777, or 644,
function getCommonMode(path) {
return statSync(path).mode.toString(8).slice(-3);
Expand Down Expand Up @@ -184,7 +186,8 @@ describe('dev/build/lib/fs', () => {
it('copies the mode of the source file', async () => {
const destination = resolve(TMP, 'dest.txt');
await copy(WORLD_EXECUTABLE, destination);
expect(getCommonMode(destination)).to.be('777');

expect(getCommonMode(destination)).to.be(isWindows ? '666' : '777');
});
});

Expand Down Expand Up @@ -225,8 +228,8 @@ describe('dev/build/lib/fs', () => {
resolve(destination, 'foo_dir/foo'),
]);

expect(getCommonMode(resolve(destination, 'bin/world_executable'))).to.be('777');
expect(getCommonMode(resolve(destination, 'foo_dir/bar.txt'))).to.be('644');
expect(getCommonMode(resolve(destination, 'bin/world_executable'))).to.be(isWindows ? '666' : '777');
expect(getCommonMode(resolve(destination, 'foo_dir/bar.txt'))).to.be(isWindows ? '666' : '644');
});

it('applies select globs if specified, ignores dot files', async () => {
Expand Down Expand Up @@ -270,6 +273,7 @@ describe('dev/build/lib/fs', () => {
expect(await read(resolve(destination, 'foo_dir/.bar'))).to.be('dotfile\n');
});


it('supports atime and mtime', async () => {
const destination = resolve(TMP, 'a/b/c/d/e');
const time = new Date(1425298511000);
Expand Down
17 changes: 15 additions & 2 deletions src/dev/build/lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,22 @@ export async function copyAll(sourceDir, destination, options = {}) {
base: sourceDir,
dot,
}),
vfs.dest(destination),
...(Boolean(time) ? [createMapStream(file => utimesAsync(file.path, time, time))] : []),
vfs.dest(destination)
]);

// we must update access and modified file times after the file copy
// has completed, otherwise the copy action can effect modify times.
if (Boolean(time)) {
await createPromiseFromStreams([
vfs.src(select, {
buffer: false,
cwd: destination,
base: destination,
dot,
}),
createMapStream(file => utimesAsync(file.path, time, time))
]);
}
}

export async function getFileHash(path, algo) {
Expand Down