Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"env": {
"node": true,
"jasmine": true
"jest/globals": true
},
"overrides": [
{
Expand Down
35,999 changes: 17,304 additions & 18,695 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,21 @@
"author": "",
"license": "Apache-2.0",
"devDependencies": {
"@types/jasmine": "^3.6.3",
"@types/mock-fs": "^4.13.0",
"@types/jest": "^29.5.12",
"@typescript-eslint/eslint-plugin": "^2.34.0",
"@typescript-eslint/parser": "^2.34.0",
"del-cli": "^3.0.1",
"eslint": "^6.6.0",
"eslint-config-google": "^0.14.0",
"jasmine": "^3.6.4",
"jest": "^29.7.0",
"jest-expect-message": "^1.1.3",
"jest-extended": "^4.0.2",
"lerna": "^6.5.1",
"lerna-changelog": "^1.0.1",
"mock-fs": "^4.13.0",
"memfs": "^4.11.1",
"npm": "^9.5.1",
"ts-jest": "^29.2.4",
"ts-node": "^8.10.2",
"typescript": "^5.5.3"
"typescript": "^5.5.4"
}
}
11 changes: 0 additions & 11 deletions packages/cli/jasmine.json

This file was deleted.

9 changes: 9 additions & 0 deletions packages/cli/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** @type {import('ts-jest').JestConfigWithTsJest} **/
module.exports = {
setupFilesAfterEnv: ["jest-extended/all"],
testEnvironment: "node",
transform: {
"^.+.tsx?$": ["ts-jest",{}],
},
verbose: true,
};
4 changes: 2 additions & 2 deletions packages/cli/package-lock.json

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

5 changes: 4 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
"build": "tsc",
"clean": "del dist",
"lint": "eslint \"src/**/*.{js,ts}\"",
"test": "tsc && jasmine --config=jasmine.json"
"test": "tsc && jest --config=jest.config.js"
},
"jest": {
"setupFilesAfterEnv": ["jest-extended/all"]
},
"files": [
"dist/lib",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
* limitations under the License.
*/

import mock from 'mock-fs';
import {vol, fs as memfs} from 'memfs';

jest.mock('fs', () => memfs);
jest.mock('fs/promises', () => memfs.promises);

import {MockLog} from '@bubblewrap/core';
import {doctor} from '../lib/cmds/doctor';
import {enUS as messages} from '../lib/strings';
Expand All @@ -24,26 +28,26 @@ describe('doctor', () => {
it('checks that the expected error message is sent in case that the path given isn\'t' +
' valid', async () => {
// Creates a mock file system.
mock({
vol.fromNestedJSON({
'path/to/sdk': {
'tools': {},
},
'path/to/config': '{"jdkPath":"path/to/jdk","androidSdkPath":"path/to/sdk"}',
});

const mockLog = new MockLog();
await expectAsync(doctor(mockLog, 'path/to/config')).toBeResolvedTo(false);
await expect(doctor(mockLog, 'path/to/config')).resolves.toBe(false);
// Check that the correct message was sent.
const logErrors: Array<string> = mockLog.getReceivedData();
const lastMessage = logErrors[logErrors.length - 1];
expect(lastMessage.indexOf('jdkPath isn\'t correct')).toBeGreaterThanOrEqual(0);
mock.restore();
vol.reset();
});

xit('checks that the expected error message is sent in case that the jdk isn\'t' +
' supported', async () => {
// Creates a mock file system.
mock({
vol.fromNestedJSON({
'path/to/jdk': {
'release': 'JAVA_VERSION="1.8',
},
Expand All @@ -54,20 +58,20 @@ describe('doctor', () => {
});

const mockLog = new MockLog();
await expectAsync(doctor(mockLog, 'path/to/config')).toBeResolvedTo(false);
await expect(doctor(mockLog, 'path/to/config')).resolves.toBe(false);
// Check that the correct message was sent.
const logErrors: Array<string> = mockLog.getReceivedData();
const lastMessage = logErrors[logErrors.length - 1];
expect(lastMessage.indexOf('Unsupported jdk version')).toBeGreaterThanOrEqual(0);
mock.restore();
vol.reset();
});
});

describe('#androidSdkDoctor', () => {
it('checks that the expected error message is sent in case that the path given isn\'t' +
' valid', async () => {
// Creates a mock file system.
mock({
vol.fromNestedJSON({
'path/to/jdk': {
'release': 'JAVA_VERSION="1.8',
},
Expand All @@ -76,12 +80,12 @@ describe('doctor', () => {

const mockLog = new MockLog();

await expectAsync(doctor(mockLog, 'path/to/config')).toBeResolvedTo(false);
await expect(doctor(mockLog, 'path/to/config')).resolves.toBe(false);

// Check that the correct message was sent.
const logErrors: Array<string> = mockLog.getReceivedData();
expect(logErrors[logErrors.length - 1]).toEqual(messages.androidSdkPathIsNotCorrect);
mock.restore();
vol.reset();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
* limitations under the License.
*/

import {vol, fs as memfs} from 'memfs';

jest.mock('fs', () => memfs);
jest.mock('fs/promises', () => memfs.promises);

import {join} from 'path';
import {homedir} from 'os';
import {existsSync} from 'fs';
import {promises as fsPromises} from 'fs';
import {loadOrCreateConfig} from '../lib/config';
import {MockLog, JdkHelper, Result, AndroidSdkTools} from '@bubblewrap/core';
import mock from 'mock-fs';
import {MockPrompt} from './mock/MockPrompt';

const DEFAULT_CONFIG_FOLDER = join(homedir(), '.bubblewrap');
Expand All @@ -33,14 +37,14 @@ const LEGACY_CONFIG_FILE_PATH = join(LEGACY_CONFIG_FOLDER, LEGACY_CONFIG_NAME);
describe('config', () => {
describe('#loadOrCreateConfig', () => {
beforeAll(() => {
spyOn(JdkHelper, 'validatePath').and.returnValue(Promise.resolve(Result.ok('/path/to/jdk')));
spyOn(AndroidSdkTools, 'validatePath').and.returnValue(Promise.resolve(Result.ok(
jest.spyOn(JdkHelper, 'validatePath').mockReturnValue(Promise.resolve(Result.ok('/path/to/jdk')));
jest.spyOn(AndroidSdkTools, 'validatePath').mockReturnValue(Promise.resolve(Result.ok(
'/path/to/android-sdk')));
});

it('checks if the file\'s name was changed in case it has the old name', async () => {
// Creates a mock file system.
mock({
vol.fromNestedJSON({
[LEGACY_CONFIG_FOLDER]: {
'llama-pack-config.json':
'{"jdkPath":"/path/to/jdk","androidSdkPath":"/path/to/android-sdk"}',
Expand All @@ -52,13 +56,13 @@ describe('config', () => {
expect(existsSync(LEGACY_CONFIG_FILE_PATH)).toBeFalse();
// Checks that the old folder was deleted.
expect(existsSync(LEGACY_CONFIG_FOLDER)).toBeFalse();
mock.restore();
vol.reset();
});

it('checks if the old config folder isn\'t deleted in case there are other files there'
, async () => {
// Creates a mock file systes.
mock({
vol.fromNestedJSON({
[LEGACY_CONFIG_FOLDER]: {
'llama-pack-config.json':
'{"jdkPath":"/path/to/jdk","androidSdkPath":"/path/to/android-sdk"}',
Expand All @@ -71,12 +75,12 @@ describe('config', () => {
expect(existsSync(LEGACY_CONFIG_FILE_PATH)).toBeFalse();
// Checks that the old folder was not deleted.
expect(existsSync(LEGACY_CONFIG_FOLDER)).toBeTrue();
mock.restore();
vol.reset();
});

it('checks if a config file is created in case there is no config file', async () => {
// Creates a mock file systes.
mock({
vol.fromNestedJSON({
[homedir()]: {},
});
const mockLog = new MockLog();
Expand All @@ -89,13 +93,13 @@ describe('config', () => {
await loadOrCreateConfig(mockLog, mockPrompt);
// Checks if the file name was created.
expect(existsSync(DEFAULT_CONFIG_FILE_PATH)).toBeTrue();
mock.restore();
vol.reset();
});

it('checks if both of the files exists in case there are old and new config files',
async () => {
// Creates a mock file systes.
mock({
vol.fromNestedJSON({
[LEGACY_CONFIG_FOLDER]: {
'llama-pack-config.json':
'{"content":"some old content",' +
Expand All @@ -116,7 +120,7 @@ describe('config', () => {
const file2 = await fsPromises.readFile(DEFAULT_CONFIG_FILE_PATH, 'utf8');
expect(file1.indexOf('old content')).toBeGreaterThanOrEqual(0);
expect(file2.indexOf('new content')).toBeGreaterThanOrEqual(0);
mock.restore();
vol.reset();
});
});
});
1 change: 1 addition & 0 deletions packages/cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"outDir": "dist",
"strict": true
},
"files": ["../../node_modules/jest-extended/types/index.d.ts"],
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "dist"]
}
11 changes: 0 additions & 11 deletions packages/core/jasmine.json

This file was deleted.

9 changes: 9 additions & 0 deletions packages/core/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** @type {import('ts-jest').JestConfigWithTsJest} **/
module.exports = {
setupFilesAfterEnv: ["jest-extended/all"],
testEnvironment: "node",
transform: {
"^.+.tsx?$": ["ts-jest", {}],
},
verbose: true,
};
4 changes: 2 additions & 2 deletions packages/core/package-lock.json

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

5 changes: 4 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
"build": "tsc",
"clean": "del dist",
"lint": "eslint \"src/**/*.{js,ts}\"",
"test": "tsc && jasmine --config=jasmine.json"
"test": "tsc && jest --config=jest.config.js"
},
"jest": {
"setupFilesAfterEnv": ["jest-extended/all"]
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('GradleWrapper', () => {
} as unknown as NodeJS.Process;

beforeEach(async () => {
spyOn(fs, 'existsSync').and.returnValue(true);
jest.spyOn(fs, 'existsSync').mockReturnValue(true);
const config = new Config('/home/user/jdk8', '/home/user/sdktools');
const jdkHelper = new JdkHelper(process, config);
androidSdkTools = await AndroidSdkTools.create(process, config, jdkHelper);
Expand All @@ -44,7 +44,7 @@ describe('GradleWrapper', () => {

describe('#bundleRelease', () => {
it('Calls "gradle bundleRelease --stacktrace"', async () => {
spyOn(util, 'executeFile').and.stub();
jest.spyOn(util, 'executeFile').mockImplementation();
await gradleWrapper.bundleRelease();
expect(util.executeFile).toHaveBeenCalledWith('./gradlew',
['bundleRelease', '--stacktrace'], androidSdkTools.getEnv(), undefined, cwd);
Expand All @@ -53,7 +53,7 @@ describe('GradleWrapper', () => {

describe('#assembleRelease', () => {
it('Calls "gradle assembleRelease --stacktrace"', async () => {
spyOn(util, 'executeFile').and.stub();
jest.spyOn(util, 'executeFile').mockImplementation();
await gradleWrapper.assembleRelease();
expect(util.executeFile).toHaveBeenCalledWith('./gradlew',
['assembleRelease', '--stacktrace'], androidSdkTools.getEnv(), undefined, cwd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import * as path from 'path';
import * as Jimp from 'jimp';
import Color = require('color');
import 'jest-expect-message';
import {ImageHelper} from '../../lib/ImageHelper';

function samePixels(actual: Jimp, expected: Jimp): void {
Expand All @@ -31,9 +32,9 @@ function samePixels(actual: Jimp, expected: Jimp): void {

if (expectedPixel.a === 0) {
// Don't care about color of transparent pixel
expect(actualPixel.a).toBe(0, `Pixel at ${x}, ${y}`);
expect(actualPixel.a, `Pixel at ${x}, ${y}`).toBe(0);
} else {
expect(actualPixel).toEqual(expectedPixel, `Pixel at ${x}, ${y}`);
expect(actualPixel, `Pixel at ${x}, ${y}`).toEqual(expectedPixel);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {vol, fs as memfs} from 'memfs';

jest.mock('fs', () => memfs);
jest.mock('fs/promises', () => memfs.promises);

import {TwaGenerator} from '../../lib/TwaGenerator';
import * as mockFs from 'mock-fs';
import {existsSync} from 'fs';

describe('TwaGenerator', () => {
Expand All @@ -26,7 +29,7 @@ describe('TwaGenerator', () => {

describe('#removeTwaProject', () => {
it('Removes project files', async () => {
mockFs({
vol.fromNestedJSON({
'/root': {
'app': {
'build.gradle': 'build.gradle content',
Expand Down Expand Up @@ -57,7 +60,7 @@ describe('TwaGenerator', () => {
expect(existsSync('/root/gradlew.bat')).toBeFalse();
expect(existsSync('/root/twa-manifest.json')).toBeTrue();
expect(existsSync('/root/android.keystore')).toBeTrue();
mockFs.restore();
vol.reset();
});
});
});
Loading