Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from julien-capellari/feature/tests
Tests
- Loading branch information
Showing
18 changed files
with
9,625 additions
and
1,014 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
version: 2 | ||
|
||
updates: | ||
# Maintain dependencies for GitHub Actions | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" | ||
|
||
# Maintain dependencies for npm/yarn | ||
- package-ecosystem: "npm" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "tests/project"] | ||
path = tests/project | ||
url = git@github.com:julien-capellari/test-is-workspace-affected.git |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"testEnvironment": "node", | ||
"roots": [ | ||
"<rootDir>/tests" | ||
], | ||
"transform": { | ||
"^.+\\.tsx?$": "ts-jest" | ||
}, | ||
"testRegex": ".+\\.(test|spec)\\.tsx?$", | ||
"moduleFileExtensions": [ | ||
"ts", | ||
"tsx", | ||
"js", | ||
"jsx", | ||
"json", | ||
"node" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Types | ||
export interface Package { | ||
name: string; | ||
version?: string; | ||
private?: boolean; | ||
workspaces?: string[]; | ||
dependencies?: Record<string, string>; | ||
devDependencies?: Record<string, string>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import * as core from '@actions/core'; | ||
import * as glob from '@actions/glob'; | ||
import * as path from 'path'; | ||
|
||
import { Workspace } from './workspace'; | ||
|
||
// Class | ||
export class Project extends Workspace { | ||
// Statics | ||
static async loadProject(root: string): Promise<Project> { | ||
return new Project(root, await this.loadPackage(root)); | ||
} | ||
|
||
// Methods | ||
private async* generateWorkspaces() { | ||
// Self ;) | ||
yield this; | ||
|
||
// Load workspaces | ||
if (this.pkg.workspaces && this.pkg.workspaces.length > 0) { | ||
const patterns = this.pkg.workspaces.map(wks => path.join(this.root, wks, 'package.json')); | ||
const globber = await glob.create(patterns.join('\n')); | ||
|
||
for await (let root of globber.globGenerator()) { | ||
root = root.replace(/[\\/]package\.json$/, ''); | ||
|
||
try { | ||
yield await Workspace.loadWorkspace(root); | ||
} catch (error) { | ||
core.warning(`Unable to load workspace at ${root}: ${error}`); | ||
} | ||
} | ||
} | ||
} | ||
|
||
async getWorkspace(name: string): Promise<Workspace | null> { | ||
for await (const wks of this.generateWorkspaces()) { | ||
if (wks.name === name) return wks; | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { promises as fs } from 'fs'; | ||
import * as path from 'path'; | ||
|
||
import { Package } from './package'; | ||
|
||
// Class | ||
export class Workspace { | ||
// Constructor | ||
protected constructor( | ||
readonly root: string, | ||
protected readonly pkg: Package | ||
) {} | ||
|
||
// Statics | ||
protected static async loadPackage(root: string): Promise<Package> { | ||
const file = path.join(root, 'package.json'); | ||
const data = await fs.readFile(file, 'utf-8'); | ||
|
||
return JSON.parse(data); | ||
} | ||
|
||
static async loadWorkspace(root: string): Promise<Workspace> { | ||
return new Workspace(root, await this.loadPackage(root)); | ||
} | ||
|
||
// Properties | ||
get name(): string { | ||
return this.pkg.name; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.