Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Commit

Permalink
Fix package command problems (#41)
Browse files Browse the repository at this point in the history
* Add first package tests

* Add more tests

* Increase timeout

* Restrict caching to ubuntu

* This aint JS

* Strings needs quotes

* Add better assumption

* Update test
  • Loading branch information
Florian Richter authored Jan 8, 2020
1 parent 1e471d8 commit a2f080a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ jobs:
- uses: actions/checkout@v1
- name: Get yarn cache directory
id: yarn-cache
if: runner.os == 'Linux'
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Save/restore yarn cache
uses: actions/cache@v1
if: runner.os == 'Linux'
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
Expand Down
12 changes: 6 additions & 6 deletions src/commands/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ export default class Package extends Command {
cwd: projectDir
})
: [];
const filtered = include.filter(filepath => !exclude.includes(filepath)).map(filepath => path.relative(projectDir, filepath));
const filtered = include.filter(filepath => !exclude.includes(filepath));

filtered.forEach(filepath => {
const outputFilePath = path.resolve(outputDir, filepath);
const outputFilePath = path.resolve(outputDir, path.relative(projectDir, filepath));
fs.mkdirSync(path.dirname(outputFilePath), { recursive: true });
fs.copyFileSync(filepath, outputFilePath);
});
Expand All @@ -102,13 +102,13 @@ export default class Package extends Command {
{
title: 'Install productive dependencies',
enabled: () => !flags.skipInstall,
task: async () => {
task: async () =>
execa('npm', ['install', '--production', '--prefix', outputDir], { stdio: flags.verbose ? 'inherit' : 'ignore' }).catch(e =>
this.error(e, { exit: 10 })
);
}
)
}
]);
tasks.run();

await tasks.run();
}
}
5 changes: 2 additions & 3 deletions test/init.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ import Init from '../src/commands/init';
import { getCleanProjectDir, getTestOutputDir } from './test-utils';

const testOutputDir = getTestOutputDir(__filename);
const expressAppDir = path.resolve('test', 'express');
const nestAppDir = path.resolve('test', 'nest');

describe('Init', () => {
const expressAppDir = path.resolve('test', 'express');
const nestAppDir = path.resolve('test', 'nest');

afterAll(() => {
fs.removeSync(testOutputDir);
});
Expand Down
49 changes: 41 additions & 8 deletions test/package.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,53 @@
* Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved.
*/

import * as fs from 'fs-extra';
import * as path from 'path';
import Package from '../src/commands/package';
import { getCleanProjectDir, getTestOutputDir } from './test-utils';

const testOutputDir = getTestOutputDir(__filename);
const nestAppDir = path.resolve('test', 'nest');

describe('Package', () => {
it('should copy files correctly without parameters', () => {
expect(true).toBeTruthy();
afterAll(() => {
fs.removeSync(testOutputDir);
});

it('should copy files correctly with custom globs', () => {
expect(true).toBeTruthy();
it('should copy files correctly without parameters', async () => {
const projectDir = getCleanProjectDir(testOutputDir, 'no-params');
fs.copySync(nestAppDir, projectDir, { recursive: true });
await Package.run([projectDir, '--skipInstall']);

const copiedFiles = fs.readdirSync(path.resolve(projectDir, 'deployment'));
expect(copiedFiles).toIncludeAllMembers(['package.json', 'package-lock.json']);
expect(copiedFiles).toHaveLength(2);
});

it('should overwrite output folder', () => {
expect(true).toBe(true);
it('should copy files correctly with custom globs', async () => {
const projectDir = getCleanProjectDir(testOutputDir, 'globs');
fs.copySync(nestAppDir, projectDir, { recursive: true });
await Package.run([projectDir, '--include=*.json', '--exclude=package*,tsconfig*', '--skipInstall']);

expect(fs.readdirSync(path.resolve(projectDir, 'deployment'))).toIncludeAllMembers(['nest-cli.json', 'tslint.json']);
expect(fs.readdirSync(path.resolve(projectDir, 'deployment'))).not.toIncludeAnyMembers(['package.json', 'package-lock.json', 'tsconfig.json']);
});

it('should install productive dependencies only', () => {
expect(true).toBe(true);
it('should overwrite output folder', async () => {
const projectDir = getCleanProjectDir(testOutputDir, 'folder-overwrite');
fs.copySync(nestAppDir, projectDir, { recursive: true });
await Package.run([projectDir, '--include=.gitignore', '--skipInstall']);
await Package.run([projectDir, '--include=README.md', '--skipInstall']);

expect(fs.readdirSync(path.resolve(projectDir, 'deployment'))).toEqual(['README.md']);
});

it('should install productive dependencies only', async () => {
const projectDir = getCleanProjectDir(testOutputDir, 'productive-dependencies');
fs.copySync(nestAppDir, projectDir, { recursive: true });
await Package.run([projectDir]);

expect(fs.readdirSync(path.resolve(projectDir, 'deployment'))).toIncludeAllMembers(['package.json', 'package-lock.json', 'node_modules']);
expect(fs.readdirSync(path.resolve(projectDir, 'deployment', 'node_modules', '@nestjs'))).not.toContain('cli');
}, 60000);
});

0 comments on commit a2f080a

Please sign in to comment.