Skip to content

Commit

Permalink
feat(test): implemented 'sasjs test' command
Browse files Browse the repository at this point in the history
  • Loading branch information
YuryShkoda committed Apr 30, 2021
1 parent f70c805 commit c77f8a9
Show file tree
Hide file tree
Showing 31 changed files with 4,140 additions and 4,863 deletions.
7,726 changes: 2,886 additions & 4,840 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@
"access": "public"
},
"dependencies": {
"@sasjs/adapter": "^2.2.13",
"@sasjs/core": "^2.13.2",
"@sasjs/adapter": "^2.2.14",
"@sasjs/core": "^2.18.1",
"@sasjs/lint": "^1.4.1",
"@sasjs/utils": "^2.8.0",
"@sasjs/utils": "^2.11.0",
"btoa": "^1.2.1",
"chalk": "^4.1.0",
"cli-table": "^0.3.6",
Expand Down Expand Up @@ -83,6 +83,7 @@
"@types/shelljs": "^0.8.8",
"babel-jest": "^26.5.0",
"copyfiles": "^2.4.1",
"ghooks": "^2.0.4",
"jest": "^26.6.3",
"jest-cli": "^26.5.0",
"jest-extended": "^0.11.5",
Expand Down
8 changes: 7 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
jobManagement,
flowManagement,
lint,
ReturnCode
ReturnCode,
test
} from './main'
import { fileExists } from './utils/file'
import path from 'path'
Expand All @@ -37,6 +38,7 @@ export async function cli(args: string[]) {

if (!parsedCommand) {
handleInvalidCommand()

return
}

Expand Down Expand Up @@ -155,6 +157,10 @@ export async function cli(args: string[]) {
result = await lint()
break
}
case 'test': {
result = await test(command)
break
}
default:
handleInvalidCommand()
result = ReturnCode.InvalidCommand
Expand Down
36 changes: 34 additions & 2 deletions src/commands/compile/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import { getAllJobFolders } from './internal/getAllJobFolders'
import { getAllServiceFolders } from './internal/getAllServiceFolders'
import { compileServiceFile } from './internal/compileServiceFile'
import { compileJobFile } from './internal/compileJobFile'
import { compileTestFile, compileTestFlow } from './internal/compileTestFile'
import {
getDestinationServicePath,
getDestinationJobPath
} from './internal/getDestinationPath'
import { moveTestFile } from './internal/compileTestFile'

export async function compile(target: Target, forceCompile = false) {
const result = await checkCompileStatus(target)
Expand All @@ -37,7 +39,11 @@ export async function compile(target: Target, forceCompile = false) {
throw error
})

await compileModule.compileJobsAndServices(target)
await compileModule.compileJobsServicesTests(target)

await compileTestFlow(target).catch((err) =>
process.logger?.error('Test flow compilation has failed.')
)
}

export async function copyFilesToBuildFolder(target: Target) {
Expand All @@ -51,11 +57,14 @@ export async function copyFilesToBuildFolder(target: Target) {
const serviceFolders = await getAllServiceFolders(target)
const jobFolders = await getAllJobFolders(target)

// REFACTOR
await asyncForEach(serviceFolders, async (serviceFolder: string) => {
const sourcePath = path.isAbsolute(serviceFolder)
? serviceFolder
: path.join(buildSourceFolder, serviceFolder)

const destinationPath = await getDestinationServicePath(sourcePath)

await copy(sourcePath, destinationPath)
})

Expand All @@ -74,12 +83,23 @@ export async function copyFilesToBuildFolder(target: Target) {
}
}

export async function compileJobsAndServices(target: Target) {
export async function compileJobsServicesTests(target: Target) {
try {
const serviceFolders = await getAllServiceFolders(target)
const jobFolders = await getAllJobFolders(target)
const macroFolders = target ? target.macroFolders : []
const programFolders = await getProgramFolders(target)
const testSetUp = target.testConfig?.testSetUp
const testTearDown = target.testConfig?.testTearDown

if (testSetUp)
await compileTestFile(target, testSetUp, macroFolders).catch((err) =>
process.logger?.error('Test set up compilation has failed.')
)
if (testTearDown)
await compileTestFile(target, testTearDown, macroFolders).catch((err) =>
process.logger?.error('Test tear down compilation has failed.')
)

await asyncForEach(serviceFolders, async (serviceFolder) => {
await compileServiceFolder(
Expand Down Expand Up @@ -130,6 +150,10 @@ const compileServiceFolder = async (
const filePath = path.join(destinationPath, fileName)

await compileServiceFile(target, filePath, macroFolders, programFolders)

await moveTestFile(filePath).catch((err) =>
process.logger?.error('Failed to move test file.')
)
})

await asyncForEach(subFolders, async (subFolder) => {
Expand All @@ -139,6 +163,10 @@ const compileServiceFolder = async (
const filePath = path.join(destinationPath, subFolder, fileName)

await compileServiceFile(target, filePath, macroFolders, programFolders)

await moveTestFile(filePath).catch((err) =>
process.logger?.error('Failed to move test file.')
)
})
})
}
Expand All @@ -161,6 +189,8 @@ const compileJobFolder = async (
const filePath = path.join(destinationPath, fileName)

await compileJobFile(target, filePath, macroFolders, programFolders)

await moveTestFile(filePath)
})

await asyncForEach(subFolders, async (subFolder) => {
Expand All @@ -170,6 +200,8 @@ const compileJobFolder = async (
const filePath = path.join(destinationPath, subFolder, fileName)

await compileJobFile(target, filePath, macroFolders, programFolders)

await moveTestFile(filePath)
})
})
}
5 changes: 4 additions & 1 deletion src/commands/compile/internal/compareFolders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
getSubFoldersInFolder,
getFilesInFolder
} from '../../../utils/file'
import { isTestFile } from './compileTestFile'

export const compareFolders = async (
sourcePath: string,
Expand All @@ -29,7 +30,9 @@ export const compareFolders = async (
destinationPath
)) as string[]

const sourceFiles = (await getFilesInFolder(sourcePath)) as string[]
const sourceFiles = (await getFilesInFolder(sourcePath).then((files) =>
files.filter((file: string) => !isTestFile(file))
)) as string[]
const destinationFiles = (await getFilesInFolder(destinationPath)) as string[]

const areSubFoldersMatching = sourceSubFolders.every((subFolder) =>
Expand Down

0 comments on commit c77f8a9

Please sign in to comment.