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

bug(amplify-cli):Solved Windows compatibility issue, made location pa… #7710

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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import execa from 'execa';
import * as fs from 'fs-extra';
import { hideSync } from 'hidefile';
import { setRegPendingDelete } from '../../utils/win-utils';
import { windowsPathSerializer } from '../testUtils/snapshot-serializer';
import * as path from 'path';

jest.mock('execa');
const execa_mock = execa as jest.Mocked<typeof execa>;
Expand Down Expand Up @@ -44,6 +46,8 @@ const setRegPendingDelete_mock = setRegPendingDelete as jest.MockedFunction<type
// save original process.platform
const originalPlatform = process.platform;

expect.addSnapshotSerializer(windowsPathSerializer);

const context_stub_typed = (context_stub as unknown) as $TSContext;

describe('uninstall packaged CLI on mac / linux', () => {
Expand All @@ -60,6 +64,7 @@ describe('uninstall packaged CLI on mac / linux', () => {
value: originalPlatform,
});
});

it('removes the .amplify dir', async () => {
await run(context_stub_typed);

Expand Down Expand Up @@ -106,7 +111,7 @@ describe('uninstall packaged CLI on windows', () => {

expect(fs_mock.move.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"homedir/.amplify/bin/amplify.exe",
"${path.join('homedir', '.amplify', 'bin', 'amplify.exe')}",
"a/test/path/.amplify-pending-delete.exe",
Object {
"overwrite": true,
Expand Down
23 changes: 13 additions & 10 deletions packages/amplify-cli/src/__tests__/commands/upgrade.pkg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { run } from '../../commands/upgrade';
import fetch, { Response } from 'node-fetch';
import { $TSContext } from 'amplify-cli-core';
import * as core from 'amplify-cli-core';

import * as path from 'path';
import { windowsPathSerializer } from '../testUtils/snapshot-serializer';
jest.mock('fs-extra');
const fs_mock = (fs as unknown) as jest.Mocked<typeof fs>;

Expand Down Expand Up @@ -45,6 +46,7 @@ const context_stub_typed = (context_stub as unknown) as $TSContext;

// save original process.platform
const originalPlatform = process.platform;
expect.addSnapshotSerializer(windowsPathSerializer);

describe('run upgrade using packaged CLI', () => {
beforeEach(() => jest.clearAllMocks());
Expand All @@ -53,7 +55,7 @@ describe('run upgrade using packaged CLI', () => {
value: originalPlatform,
});
});

it('exits early if no new packaged version available', async () => {
// setup
fetch_mock.mockResolvedValueOnce(({
Expand Down Expand Up @@ -98,16 +100,17 @@ describe('run upgrade using packaged CLI', () => {
// validate
expect(fs_mock.move.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"homedir/bin/amplify-pkg-linux",
"homedir/bin/amplify",
"${path.join('homedir', 'bin', 'amplify-pkg-linux')}",
"${path.join('homedir', 'bin', 'amplify')}",
Object {
"overwrite": true,
},
]
`);

expect(fs_mock.chmod.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"homedir/bin/amplify",
"${path.join('homedir', 'bin', 'amplify')}",
"700",
]
`);
Expand Down Expand Up @@ -149,22 +152,22 @@ describe('run upgrade using packaged CLI', () => {
// validate
expect(fs_mock.move.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"homedir/bin/amplify.exe",
"homedir/bin/amplify-old.exe",
"${path.join('homedir', 'bin', 'amplify.exe')}",
"${path.join('homedir', 'bin', 'amplify-old.exe')}",
]
`);
expect(fs_mock.move.mock.calls[1]).toMatchInlineSnapshot(`
Array [
"homedir/bin/amplify-pkg-win.exe",
"homedir/bin/amplify.exe",
"${path.join('homedir', 'bin', 'amplify-pkg-win.exe')}",
"${path.join('homedir', 'bin', 'amplify.exe')}",
Object {
"overwrite": true,
},
]
`);
expect(fs_mock.chmod.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"homedir/bin/amplify.exe",
"${path.join('homedir', 'bin', 'amplify.exe')}",
"700",
]
`);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const originalPlatform = process.platform;

// converts inputs to toMatchInlineSnapshot() function into supported format
export const windowsPathSerializer = {
test(val) {
return typeof val === 'string' && originalPlatform === 'win32';
},
print(val) {
return `"${(val as string).replace(/\\/g, '\\')}"`;
}
};

test('validateWindowsPathSerializer', () => {
expect(windowsPathSerializer).toBeDefined();
});