Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Jul 11, 2022
1 parent 5969b0a commit e4f0a10
Showing 1 changed file with 62 additions and 2 deletions.
64 changes: 62 additions & 2 deletions e2e/nx-run/src/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import {
listFiles,
newProject,
readFile,
removeFile,
rmDist,
runCLI,
runCLIAsync,
uniq,
updateFile,
updateJson,
Expand All @@ -16,7 +18,7 @@ describe('cache', () => {

afterAll(() => cleanupProject());

it('should cache command execution', async () => {
it('tttshould cache command execution', async () => {
const myapp1 = uniq('myapp1');
const myapp2 = uniq('myapp2');
runCLI(`generate @nrwl/web:app ${myapp1}`);
Expand Down Expand Up @@ -99,7 +101,7 @@ describe('cache', () => {
expect(outputWithBothLintTasksCached).toContain(
'read the output from the cache'
);
expectCached(outputWithBothLintTasksCached, [
expectMatchedOutput(outputWithBothLintTasksCached, [
myapp1,
myapp2,
`${myapp1}-e2e`,
Expand Down Expand Up @@ -164,6 +166,64 @@ describe('cache', () => {
updateFile('nx.json', (c) => originalNxJson);
}, 120000);

it('should support using globs as outputs', async () => {
const mylib = uniq('mylib');
runCLI(`generate @nrwl/workspace:library ${mylib}`);
updateProjectConfig(mylib, (c) => {
c.targets.build = {
executor: 'nx:run-commands',
outputs: ['dist'],
options: {
commands: [
'rm -rf dist',
'mkdir dist',
'echo a > dist/a.txt',
'echo b > dist/b.txt',
],
parallel: false,
},
};
return c;
});

// Run without cache
const runWithoutCache = runCLI(`build ${mylib}`);
expect(runWithoutCache).not.toContain('read the output from the cache');

// Rerun without touching anything
const rerunWithUntouchedOutputs = runCLI(`build ${mylib}`);
expect(rerunWithUntouchedOutputs).toContain(
'existing outputs match the cache'
);
const outputsWithUntouchedOutputs = listFiles('dist');
expect(outputsWithUntouchedOutputs).toContain('a.txt');
expect(outputsWithUntouchedOutputs).toContain('b.txt');

// Create a file in the dist that does not match output glob
updateFile('dist/c.ts', '');

// Rerun
const rerunWithNewUnrelatedFile = runCLI(`build ${mylib}`);
expect(rerunWithNewUnrelatedFile).toContain(
'existing outputs match the cache'
);
const outputsAfterAddingUntouchedFileAndRerunning = listFiles('dist');
expect(outputsAfterAddingUntouchedFileAndRerunning).toContain('a.txt');
expect(outputsAfterAddingUntouchedFileAndRerunning).toContain('b.txt');
expect(outputsAfterAddingUntouchedFileAndRerunning).toContain('c.ts');

// Clear Dist
rmDist();

// Rerun
const rerunWithoutOutputs = runCLI(`build ${mylib}`);
expect(rerunWithoutOutputs).toContain('read the output from the cache');
const outputsWithoutOutputs = listFiles('dist');
expect(outputsWithoutOutputs).toContain('a.txt');
expect(outputsWithoutOutputs).toContain('b.txt');
expect(outputsWithoutOutputs).not.toContain('c.ts');
});

it('should use consider filesets when hashing', async () => {
const parent = uniq('parent');
const child1 = uniq('child1');
Expand Down

0 comments on commit e4f0a10

Please sign in to comment.