Merge pull request #3852 from backstage/freben/linked-win32
cli: fix LinkedPackageResolvePlugin windows tests
This commit is contained in:
@@ -14,20 +14,27 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import { LinkedPackageResolvePlugin } from './LinkedPackageResolvePlugin';
|
||||
|
||||
describe('LinkedPackageResolvePlugin', () => {
|
||||
const root = os.platform() === 'win32' ? 'C:\\root' : '/root';
|
||||
|
||||
it('should re-write paths for external packages', () => {
|
||||
const plugin = new LinkedPackageResolvePlugin('/root/repo/node_modules', [
|
||||
{
|
||||
name: 'a',
|
||||
location: '/root/external-a',
|
||||
},
|
||||
{
|
||||
name: '@s/b',
|
||||
location: '/root/external-b',
|
||||
},
|
||||
]);
|
||||
const plugin = new LinkedPackageResolvePlugin(
|
||||
path.resolve(root, 'repo/node_modules'),
|
||||
[
|
||||
{
|
||||
name: 'a',
|
||||
location: path.resolve(root, 'external-a'),
|
||||
},
|
||||
{
|
||||
name: '@s/b',
|
||||
location: path.resolve(root, 'external-b'),
|
||||
},
|
||||
],
|
||||
);
|
||||
|
||||
const tapAsync = jest.fn();
|
||||
const doResolve = jest.fn();
|
||||
@@ -50,10 +57,10 @@ describe('LinkedPackageResolvePlugin', () => {
|
||||
const callbackX = jest.fn();
|
||||
tap(
|
||||
{
|
||||
request: '/root/repo/package/x/src/module.ts',
|
||||
path: '/root/repo/package/x/src',
|
||||
request: path.resolve(root, 'repo/package/x/src/module.ts'),
|
||||
path: path.resolve(root, 'repo/package/x/src'),
|
||||
context: {
|
||||
issuer: '/root/repo/package/x/src/index.ts',
|
||||
issuer: path.resolve(root, 'repo/package/x/src/index.ts'),
|
||||
},
|
||||
},
|
||||
'some-context',
|
||||
@@ -81,10 +88,10 @@ describe('LinkedPackageResolvePlugin', () => {
|
||||
const callbackA = jest.fn();
|
||||
tap(
|
||||
{
|
||||
request: '/root/external-a/src/module.ts',
|
||||
path: '/root/external-a/src',
|
||||
request: path.resolve(root, 'external-a/src/module.ts'),
|
||||
path: path.resolve(root, 'external-a/src'),
|
||||
context: {
|
||||
issuer: '/root/external-a/src/index.ts',
|
||||
issuer: path.resolve(root, 'external-a/src/index.ts'),
|
||||
},
|
||||
},
|
||||
'some-context',
|
||||
@@ -95,13 +102,16 @@ describe('LinkedPackageResolvePlugin', () => {
|
||||
expect(doResolve).toHaveBeenCalledWith(
|
||||
resolver.hooks.resolve,
|
||||
{
|
||||
request: '/root/external-a/src/module.ts',
|
||||
path: '/root/repo/node_modules/a/src',
|
||||
request: path.resolve(root, 'external-a/src/module.ts'),
|
||||
path: path.resolve(root, 'repo/node_modules/a/src'),
|
||||
context: {
|
||||
issuer: '/root/repo/node_modules/a/src/index.ts',
|
||||
issuer: path.resolve(root, 'repo/node_modules/a/src/index.ts'),
|
||||
},
|
||||
},
|
||||
'resolve /root/external-a/src/module.ts in /root/repo/node_modules/a',
|
||||
`resolve ${path.resolve(
|
||||
root,
|
||||
'external-a/src/module.ts',
|
||||
)} in ${path.resolve(root, 'repo/node_modules/a')}`,
|
||||
'some-context',
|
||||
callbackA,
|
||||
);
|
||||
@@ -110,8 +120,8 @@ describe('LinkedPackageResolvePlugin', () => {
|
||||
const callbackB = jest.fn();
|
||||
tap(
|
||||
{
|
||||
request: '/root/external-b/src/module.ts',
|
||||
path: '/root/external-b/src',
|
||||
request: path.resolve(root, 'external-b/src/module.ts'),
|
||||
path: path.resolve(root, 'external-b/src'),
|
||||
context: {
|
||||
issuer: false,
|
||||
},
|
||||
@@ -124,13 +134,16 @@ describe('LinkedPackageResolvePlugin', () => {
|
||||
expect(doResolve).toHaveBeenLastCalledWith(
|
||||
resolver.hooks.resolve,
|
||||
{
|
||||
request: '/root/external-b/src/module.ts',
|
||||
path: '/root/repo/node_modules/@s/b/src',
|
||||
request: path.resolve(root, 'external-b/src/module.ts'),
|
||||
path: path.resolve(root, 'repo/node_modules/@s/b/src'),
|
||||
context: {
|
||||
issuer: false,
|
||||
},
|
||||
},
|
||||
'resolve /root/external-b/src/module.ts in /root/repo/node_modules/@s/b',
|
||||
`resolve ${path.resolve(
|
||||
root,
|
||||
'external-b/src/module.ts',
|
||||
)} in ${path.resolve(root, 'repo/node_modules/@s/b')}`,
|
||||
'some-context',
|
||||
callbackB,
|
||||
);
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import mockFs from 'mock-fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import { getFileTreeRecursively, getHeadersForFileExtension } from './helpers';
|
||||
|
||||
describe('getHeadersForFileExtension', () => {
|
||||
@@ -39,9 +41,11 @@ describe('getHeadersForFileExtension', () => {
|
||||
});
|
||||
|
||||
describe('getFileTreeRecursively', () => {
|
||||
const root = os.platform() === 'win32' ? 'C:\\rootDir' : '/rootDir';
|
||||
|
||||
beforeEach(() => {
|
||||
mockFs({
|
||||
'/rootDir': {
|
||||
[root]: {
|
||||
file1: '',
|
||||
subDirA: {
|
||||
file2: '',
|
||||
@@ -57,9 +61,9 @@ describe('getFileTreeRecursively', () => {
|
||||
});
|
||||
|
||||
it('returns complete file tree of a path', async () => {
|
||||
const fileList = await getFileTreeRecursively('/rootDir');
|
||||
const fileList = await getFileTreeRecursively(root);
|
||||
expect(fileList.length).toBe(2);
|
||||
expect(fileList).toContain('/rootDir/file1');
|
||||
expect(fileList).toContain('/rootDir/subDirA/file2');
|
||||
expect(fileList).toContain(path.resolve(root, 'file1'));
|
||||
expect(fileList).toContain(path.resolve(root, 'subDirA/file2'));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user