Skip to content

Commit

Permalink
refactor(js-toolkit): make tests work in monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
wincent committed Oct 6, 2020
1 parent 47c938c commit 3cad687
Show file tree
Hide file tree
Showing 14 changed files with 1,944 additions and 880 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,29 @@ jobs:
- run: yarn --cache-folder=${{ env.yarn-cache-path }} --frozen-lockfile
- run: yarn --cache-folder=${{ env.yarn-cache-path }} test

test-js-toolkit:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Use or update Yarn cache
uses: actions/cache@v2
with:
path: ${{ env.yarn-cache-path }}
key: ${{ runner.os }}-${{ env.yarn-cache-name }}-${{ hashFiles('**/yarn.lock') }}-js-toolkit
- run: yarn --cache-folder=../../../${{ env.yarn-cache-path }} --frozen-lockfile
working-directory: maintenance/projects/js-toolkit
- run: yarn --cache-folder=../../../${{ env.yarn-cache-path }} test
working-directory: maintenance/projects/js-toolkit

test-windows:
runs-on: windows-latest

Expand Down
19 changes: 17 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
*/

module.exports = {
modulePathIgnorePatterns: [
'<rootDir>/maintenance/',
'__fixtures__/.*',
],
projects: [
// Projects which require special configuration.

'projects/eslint-config/jest.config.js',
'projects/js-toolkit/jest.config.js',
'projects/npm-tools/packages/npm-scripts/jest.config.js',

// Everything else.
Expand All @@ -19,11 +24,21 @@ module.exports = {
'jest.config.js',
],
testMatch: ['**/test/**/*.js'],
testPathIgnorePatterns: [
// Projects in maintenance mode which do not participate in the
// top-level set of Yarn workspaces.

// Any project which had special configuration above should be ignored here.
'<rootDir>/maintenance',

// Any project which had special configuration above should be
// ignored here.

testPathIgnorePatterns: [
'<rootDir>/projects/eslint-config',
'<rootDir>/projects/js-toolkit',
'<rootDir>/projects/npm-tools/packages/npm-scripts',

// Standard ignores.

'/node_modules/',
],
};
9 changes: 0 additions & 9 deletions maintenance/projects/js-toolkit/.travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion maintenance/projects/js-toolkit/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {
'qa/.*',
'__fixtures__/.*',
],
testPathIgnorePatterns: ['/node_modules/', '/__fixtures__/'],
testPathIgnorePatterns: ['/qa/samples/', '/__fixtures__/'],
transform: {
'\\.js$': 'ts-jest',
'\\.ts$': 'ts-jest',
Expand Down
5 changes: 2 additions & 3 deletions maintenance/projects/js-toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
"copyfiles": "^2.1.1",
"fs-extra": "^8.1.0",
"globby": "^10.0.1",
"jest": "^24.9.0",
"jest": "^26.4.2",
"lerna": "^3.16.4",
"prettier": "1.18.2",
"ts-jest": "^24.1.0",
"ts-jest": "^26.4.1",
"typescript": "^3.6.3",
"yo": "^3.1.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class Manifest {
this._filePath = filePath;

try {
this._data = JSON.parse(fs.readFileSync(filePath));
this._data = JSON.parse(fs.readFileSync(filePath, 'utf8'));
this._loadedFromFile = true;

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ it('logs results correctly', () => {
{
level: 'info',
source: 'sass-loader',
things: ['Processed file with sass v1.24.0 (from project)'],
things: ['Processed file with node-sass v4.14.1 (from project)'],
},
]);
});
Expand All @@ -41,8 +41,8 @@ it('correctly generates CSS', () => {
const result = loader(context, {});

expect(result).toEqual(`.Button {
border: 1px solid red;
}`);
border: 1px solid red; }
`);

expect(Object.keys(context.extraArtifacts)).toEqual([]);
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,40 @@ import PluginLogger from 'liferay-npm-build-tools-common/lib/plugin-logger';
import {reportAndResolveCollisions} from '../index';
import {UnrolledAliasesMap} from '../util';

const date = new Date();

const fakeStats: ReturnType<typeof fs.statSync> = {
atime: date,
atimeMs: +date,
atimeNs: BigInt(+date * 1000),
birthtime: date,
birthtimeMs: +date,
birthtimeNs: BigInt(+date * 1000),
blksize: 1000,
blocks: 1000,
ctime: date,
ctimeMs: +date,
ctimeNs: BigInt(+date * 1000),
dev: 100,
gid: 100,
ino: 100,
isBlockDevice: () => false,
isCharacterDevice: () => false,
isDirectory: () => false,
isFIFO: () => false,
isFile: () => true,
isSocket: () => false,
isSymbolicLink: () => false,
mode: 0,
mtime: date,
mtimeMs: +date,
mtimeNs: BigInt(+date * 1000),
nlink: 1000,
rdev: 1000,
size: 1000,
uid: 1000,
};

describe('reportAndResolveCollisions', () => {
const absRootDir = new FilePath('/home/me/project');
let log;
Expand Down Expand Up @@ -56,9 +90,7 @@ describe('reportAndResolveCollisions', () => {
],
};

jest.spyOn(fs, 'statSync').mockReturnValue({
isFile: () => true,
});
jest.spyOn(fs, 'statSync').mockReturnValue(fakeStats);

reportAndResolveCollisions(log, absRootDir, unrolledAliasMap);

Expand Down Expand Up @@ -147,9 +179,7 @@ describe('reportAndResolveCollisions', () => {
],
};

jest.spyOn(fs, 'statSync').mockReturnValue({
isFile: () => true,
});
jest.spyOn(fs, 'statSync').mockReturnValue(fakeStats);

reportAndResolveCollisions(log, absRootDir, unrolledAliasMap);

Expand Down
Loading

0 comments on commit 3cad687

Please sign in to comment.