Skip to content

Commit

Permalink
Move to root fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristiano Belloni committed Aug 18, 2022
1 parent 53d1338 commit 876b607
Show file tree
Hide file tree
Showing 72 changed files with 25 additions and 48 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
40 changes: 6 additions & 34 deletions packages/modular-scripts/src/__tests__/test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,34 +82,22 @@ describe('Modular test command', () => {
describe('test command can successfully do selective tests based on the state of the repository', () => {
const fixturesFolder = path.join(
__dirname,
Array.from({ length: 4 }).reduce<string>(
(acc) => `${acc}..${path.sep}`,
'',
),
'__fixtures__',
'ghost-testing',
);

const currentModularFolder = getModularRoot();
let randomOutputFolder: string;

beforeEach(async () => {
beforeEach(() => {
// Create random dir
randomOutputFolder = tmp.dirSync({ unsafeCleanup: true }).name;
fs.copySync(fixturesFolder, randomOutputFolder);

// Get all the files, recursively, and rename the .incognito files
const fileList = await getFileList(randomOutputFolder);
// Generate an array of promises that we can wait parallely on with Promise.all
await Promise.all(
fileList.reduce<Promise<void>[]>((acc, filePath) => {
if (path.basename(filePath) === 'package.json.incognito') {
acc.push(
fs.rename(
filePath,
path.join(path.dirname(filePath), 'package.json'),
),
);
}
return acc;
}, []),
);

// Create git repo & commit
if (process.env.GIT_AUTHOR_NAME && process.env.GIT_AUTHOR_EMAIL) {
execa.sync('git', [
Expand Down Expand Up @@ -228,19 +216,3 @@ function runRemoteModularTest(
},
);
}

// Recursively get all files in a directory and its subdirectories
async function getFileList(dirName: string): Promise<string[]> {
let files: string[] = [];
const items = await fs.readdir(dirName, { withFileTypes: true });

for (const item of items) {
if (item.isDirectory()) {
files = [...files, ...(await getFileList(`${dirName}/${item.name}`))];
} else {
files.push(`${dirName}/${item.name}`);
}
}

return files;
}
33 changes: 19 additions & 14 deletions packages/workspace-resolver/src/__tests__/resolve-workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ import path from 'path';
const dirsUp = 4;
const traverseUp = Array.from({ length: dirsUp })
.map(() => `..`)
.join(path.sep)
.concat(path.sep);
const fixturesPath = `${__dirname}${path.sep}${traverseUp}__fixtures__${path.sep}`;
.join(path.sep);

const fixturesPath = path.join(
__dirname,
traverseUp,
'__fixtures__',
'resolve-workspace',
);

describe('@modular-scripts/workspace-resolver', () => {
describe('resolveWorkspace', () => {
it('resolves a clean workspace, detecting modular packages as appropriate', async () => {
const projectRoot = `${fixturesPath}clean-workspace-1`;
const projectRoot = path.join(fixturesPath, 'clean-workspace-1');
const [allPackages] = await resolveWorkspace(projectRoot, projectRoot);
expect(allPackages.has('clean-workspace-1')).toEqual(true);
expect(allPackages.has('app-one')).toEqual(true);
Expand All @@ -28,7 +33,7 @@ describe('@modular-scripts/workspace-resolver', () => {
// This covers the alternative object workspaces syntax that yarn supports
// See https://classic.yarnpkg.com/blog/2018/02/15/nohoist/
it('resolves a clean workspace (using object workspaces syntax)', async () => {
const projectRoot = `${fixturesPath}clean-workspace-2`;
const projectRoot = path.join(fixturesPath, 'clean-workspace-2');
const [allPackages] = await resolveWorkspace(projectRoot, projectRoot);
expect(allPackages.has('clean-workspace-2')).toEqual(true);
expect(allPackages.has('app-one')).toEqual(true);
Expand All @@ -37,7 +42,7 @@ describe('@modular-scripts/workspace-resolver', () => {
});

it('resolves a clean workspace (using workspace ranges)', async () => {
const projectRoot = `${fixturesPath}clean-workspace-3`;
const projectRoot = path.join(fixturesPath, 'clean-workspace-3');
const [allPackages] = await resolveWorkspace(projectRoot, projectRoot);
expect(allPackages.has('clean-workspace-3')).toEqual(true);
expect(allPackages.has('app-one')).toEqual(true);
Expand All @@ -48,7 +53,7 @@ describe('@modular-scripts/workspace-resolver', () => {
});

it('does not support nested modular roots', async () => {
const projectRoot = `${fixturesPath}invalid-workspace-1`;
const projectRoot = path.join(fixturesPath, 'invalid-workspace-1');
let thrown = false;
let message = '';

Expand All @@ -68,7 +73,7 @@ describe('@modular-scripts/workspace-resolver', () => {
});

it('does not support nested yarn workspaces (implementation 1)', async () => {
const projectRoot = `${fixturesPath}invalid-workspace-2`;
const projectRoot = path.join(fixturesPath, 'invalid-workspace-2');
let thrown = false;
let message = '';

Expand All @@ -88,7 +93,7 @@ describe('@modular-scripts/workspace-resolver', () => {
});

it('does not support nested yarn workspaces (implementation 2)', async () => {
const projectRoot = `${fixturesPath}invalid-workspace-3`;
const projectRoot = path.join(fixturesPath, 'invalid-workspace-3');
let thrown = false;
let message = '';

Expand All @@ -108,7 +113,7 @@ describe('@modular-scripts/workspace-resolver', () => {
});

it('does not support packages with no name', async () => {
const projectRoot = `${fixturesPath}invalid-workspace-4`;
const projectRoot = path.join(fixturesPath, 'invalid-workspace-4');
let thrown = false;
let message = '';

Expand All @@ -128,7 +133,7 @@ describe('@modular-scripts/workspace-resolver', () => {
});

it('does not support packages with no version', async () => {
const projectRoot = `${fixturesPath}invalid-workspace-5`;
const projectRoot = path.join(fixturesPath, 'invalid-workspace-5');
let thrown = false;
let message = '';

Expand All @@ -150,7 +155,7 @@ describe('@modular-scripts/workspace-resolver', () => {

describe('analyzeWorkspaceDependencies', () => {
it('correctly identifies workspace dependencies for a clean workspace', async () => {
const projectRoot = `${fixturesPath}clean-workspace-1`;
const projectRoot = path.join(fixturesPath, 'clean-workspace-1');
const [allPackages] = await resolveWorkspace(projectRoot, projectRoot);

const result = analyzeWorkspaceDependencies(allPackages);
Expand All @@ -175,7 +180,7 @@ describe('@modular-scripts/workspace-resolver', () => {
});

it('correctly identifies mismatched dependencies', async () => {
const projectRoot = `${fixturesPath}mismatched-dependency`;
const projectRoot = path.join(fixturesPath, 'mismatched-dependency');
const [allPackages] = await resolveWorkspace(projectRoot, projectRoot);

const result = analyzeWorkspaceDependencies(allPackages);
Expand All @@ -200,7 +205,7 @@ describe('@modular-scripts/workspace-resolver', () => {
});

it('correctly identifies dependencies (workspace range)', async () => {
const projectRoot = `${fixturesPath}clean-workspace-3`;
const projectRoot = path.join(fixturesPath, 'clean-workspace-3');
const [allPackages] = await resolveWorkspace(projectRoot, projectRoot);

// Matches explanation (version 1.0.0):
Expand Down

0 comments on commit 876b607

Please sign in to comment.