Skip to content

Commit

Permalink
fix(tests): fix import used in tests for glob
Browse files Browse the repository at this point in the history
  • Loading branch information
azlam-abdulsalam committed Aug 8, 2023
1 parent 185b6fb commit 3ead60e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
2 changes: 2 additions & 0 deletions packages/core/src/apextest/ApexTestSuite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export default class ApexTestSuite {
absolute: true,
});

console.log('testSuitePaths',testSuitePaths);

if (!testSuitePaths[0]) throw new Error(`Apex Test Suite ${this.suiteName} not found`);

let apex_test_suite: any = await xml2json(fs.readFileSync(path.resolve(testSuitePaths[0])));
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/artifacts/ArtifactFetcher.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path = require('path');
import * as fs from 'fs-extra';
import SFPLogger, { Logger, LoggerLevel } from '@dxatscale/sfp-logger';
const { globSync } = require('glob');
import { globSync } from 'glob';
import AdmZip = require('adm-zip');
import semver = require('semver');
import tar = require('tar');
Expand Down
24 changes: 15 additions & 9 deletions packages/core/tests/apextest/ApexTestSuite.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { jest, expect } from '@jest/globals';
const fs = require('fs-extra');
import ApexTestSuite from '../../src/apextest/ApexTestSuite';
const glob = require('glob');
import * as globSync from 'glob';



describe('Provided an apex test suite from a source directory', () => {
it('should return all the apexclasses', () => {
const globMock = jest.spyOn(glob, 'sync');
globMock.mockImplementation(() => {


jest.spyOn(globSync, 'globSync').mockImplementationOnce((pattern: string | string[], options: any) => {
return new Array('/path/to/test.testSuite-meta.xml');
});


const fsReadMock = jest.spyOn(fs, 'readFileSync');
fsReadMock.mockImplementationOnce(() => {
return `
Expand All @@ -36,20 +40,22 @@ describe('Provided an apex test suite from a source directory', () => {
});

it('should throw an error if apex test suite is not avaiable in the directory', async () => {
const globMock = jest.spyOn(glob, 'sync');
globMock.mockImplementation(() => {
return [];

jest.spyOn(globSync, 'globSync').mockImplementationOnce((pattern: string | string[], options: any) => {
return [];
});



let apexTestSuite = new ApexTestSuite(`dir`, `test`);

expect(apexTestSuite.getConstituentClasses()).rejects.toThrowError();
});

it('should return apexclass even if there is only one', () => {
const globMock = jest.spyOn(glob, 'sync');
globMock.mockImplementation(() => {
return new Array('/path/to/test.testSuite-meta.xml');

jest.spyOn(globSync, 'globSync').mockImplementationOnce((pattern: string | string[], options: any) => {
return new Array('/path/to/test.testSuite-meta.xml');;
});

const fsReadMock = jest.spyOn(fs, 'readFileSync');
Expand Down
23 changes: 13 additions & 10 deletions packages/core/tests/artifacts/ArtifactsFromFileSystem.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { jest, expect } from '@jest/globals';
const glob = require('glob');
import ArtifactFetcher from '../../src/artifacts/ArtifactFetcher';
import * as globSync from 'glob';

describe('Provided a path to the artifacts folder containing sfpowerscripts artifact', () => {
it('should return all the artifacts, if a package name is not provided', () => {
const globMock = jest.spyOn(glob, 'sync');
globMock.mockImplementation(() => {

jest.spyOn(globSync, 'globSync').mockImplementationOnce((pattern: string | string[], options: any) => {
return [
'/path/to/core_sfpowerscripts_artifact_1.0.0-2.zip',
'/path/to/core2_sfpowerscripts_artifact_1.0.0-2.zip',
'/path/to/core3_sfpowerscripts_artifact_1.0.0-3.zip',
'/path/to/my-package_sfpowerscripts_artifact_3.30.53-NEXT.tgz'
];
});
});


let artifacts = ArtifactFetcher.findArtifacts('artifacts');
expect(artifacts).toEqual(
[
Expand All @@ -25,24 +27,25 @@ describe('Provided a path to the artifacts folder containing sfpowerscripts arti
});

it('provided only one artifact exists for a package and a package name is provided, it should just return the one artifact', () => {
const globMock = jest.spyOn(glob, 'sync');
globMock.mockImplementation(() => {

jest.spyOn(globSync, 'globSync').mockImplementationOnce((pattern: string | string[], options: any) => {
return new Array('/path/to/core_sfpowerscripts_artifact_1.0.0-2.zip');
});
});

let artifacts = ArtifactFetcher.findArtifacts('artifacts', 'core');
expect(artifacts).toEqual(new Array('/path/to/core_sfpowerscripts_artifact_1.0.0-2.zip'));
});

it('provided multiple artifacts of the same package exists and a package name is provied, it should return the latest', () => {
const globMock = jest.spyOn(glob, 'sync');
globMock.mockImplementation(() => {

jest.spyOn(globSync, 'globSync').mockImplementationOnce((pattern: string | string[], options: any) => {
return [
'/path/to/core_sfpowerscripts_artifact_1.0.0-2.zip',
'/path/to/core_sfpowerscripts_artifact_1.0.0-3.zip',
'/path/to/core_sfpowerscripts_artifact_1.0.0-4.zip',
'/path/to/core_sfpowerscripts_artifact_1.0.0-5.tgz'
];
});
});
let artifacts = ArtifactFetcher.findArtifacts('artifacts', 'core');
expect(artifacts).toEqual(new Array('/path/to/core_sfpowerscripts_artifact_1.0.0-5.tgz'));
});
Expand Down

0 comments on commit 3ead60e

Please sign in to comment.