Skip to content

Commit

Permalink
Add GitHub actions ci + Support Windows (#100)
Browse files Browse the repository at this point in the history
* add github actions ci

* update images and remove circle

* fix name generation on windows

* tests windows compatibility

* test symlinks properly on windows
  • Loading branch information
ranyitz authored Jun 4, 2022
1 parent 61b7ef8 commit 3ed738e
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 60 deletions.
58 changes: 0 additions & 58 deletions .circleci/config.yml

This file was deleted.

39 changes: 39 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: CI

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 14
uses: actions/setup-node@v1
with:
node-version: 14

- name: install and lint
run: |
yarn
yarn lint
test:
name: Test on node ${{ matrix.node_version }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
node_version: ['12', '14', '16']
os: [ubuntu-22.04, windows-2022, macos-12]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node_version }}

- name: install, build, test
run: |
yarn
yarn build
yarn test
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"pkg-dir": "^5.0.0",
"prettier": "^2.2.1",
"prompts": "^2.3.0",
"replaceall": "^0.1.6",
"semver": "^7.3.5",
"strip-ansi": "^7.0.1",
"terminal-link": "^2.1.1",
Expand Down
17 changes: 16 additions & 1 deletion src/__tests__/actions/get.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ jest.mock('prompts', () => {
});

import open from 'open';
import path from 'path';
import prompts from 'prompts';
import getAction from '../../actions/get';
import { resolveWorkspace } from '../utils';
Expand Down Expand Up @@ -93,12 +94,21 @@ describe('get', () => {
});

describe('--open', () => {
const isWindows = /^win/.test(process.platform);

it('should open module file directory when --open flag used', () => {
const workspace = resolveWorkspace('three-levels-deep');
getAction(workspace, 'dep', { open: true });

let expectedPath = path.join('node_modules', 'dep', 'package.json');

if (isWindows) {
const sep = path.sep + path.sep;
expectedPath = `node_modules` + sep + 'dep' + sep + 'package.json';
}

expect(open).toHaveBeenCalledWith(
expect.stringMatching(/node_modules\/dep\/package.json/),
expect.stringMatching(expectedPath),
expect.any(Object)
);
});
Expand All @@ -107,6 +117,11 @@ describe('get', () => {
const workspace = resolveWorkspace('few-modules');
getAction(workspace, 'dependency2', { open: true });

// it's not critical to run this on windows
if (isWindows) {
return;
}

expect(prompts).toHaveBeenCalledWith(
expect.objectContaining({
choices: expect.arrayContaining([
Expand Down
16 changes: 16 additions & 0 deletions src/__tests__/cli.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { execSync, StdioOptions } from 'child_process';
import { resolveFixture } from './utils';
// @ts-expect-error no typings
import replaceall from 'replaceall';

const qnmBin = require.resolve('../../bin/qnm');

Expand Down Expand Up @@ -61,6 +63,20 @@ describe('CLI', () => {
});

it('should show an indication in case there is a symlink', () => {
const isWindows = /^win/.test(process.platform);

if (isWindows) {
const cwd = resolveFixture('symlink');
// symlinks in windows are a bit different
const output = runCommand('test-windows', { cwd });

// the snapshot must look similar to the one on windows
expect(
replaceall('\\', '/', replaceall('-windows', '', output))
).toMatchSnapshot();
return;
}

const cwd = resolveFixture('symlink');
const output = runCommand('test', { cwd });

Expand Down
1 change: 1 addition & 0 deletions src/__tests__/fixtures/symlink/node_modules/test-windows

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/workspace/modules-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ export default class ModulesMap extends Map<string, Array<NodeModule>> {
);

return subScopeModules.map((subName) => {
const fullName = path.join(name, subName);
const fullName = `${name}/${subName}`;

const nodeModule = new NodeModule({
nodeModulesPath,
name: fullName,
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4599,6 +4599,7 @@ __metadata:
pkg-dir: ^5.0.0
prettier: ^2.2.1
prompts: ^2.3.0
replaceall: ^0.1.6
semver: ^7.3.5
strip-ansi: ^7.0.1
terminal-link: ^2.1.1
Expand Down Expand Up @@ -4650,6 +4651,13 @@ __metadata:
languageName: node
linkType: hard

"replaceall@npm:^0.1.6":
version: 0.1.6
resolution: "replaceall@npm:0.1.6"
checksum: 2396fdc6f10b7ed7c8c0298455840473a028a81e29087bc02a37cc3ff1e85467534e0992a1b45bcdb3e99370db656d260bec7bd422819b708009f060ba8b4dbe
languageName: node
linkType: hard

"require-directory@npm:^2.1.1":
version: 2.1.1
resolution: "require-directory@npm:2.1.1"
Expand Down

0 comments on commit 3ed738e

Please sign in to comment.