Skip to content

Commit

Permalink
fix tests for windows/linux
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomontero committed Nov 23, 2023
1 parent e35d548 commit 1e74fb4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/cmd/logic-function.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const settings = require('../../settings');
const { normalizedApiError } = require('../lib/api-client');
const { copyAndReplaceTemplate, hasTemplateFiles } = require('../lib/template-processor');

const logicFunctionTemplatePath = __dirname + '/../../assets/logicFunction';
const logicFunctionTemplatePath = path.join(__dirname, '/../../assets/logicFunction');

/**
* Commands for managing encryption keys.
Expand Down
13 changes: 9 additions & 4 deletions src/cmd/logic-function.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const nock = require('nock');
const { expect, sinon } = require('../../test/setup');
const LogicFunctionCommands = require('./logic-function');
const { PATH_FIXTURES_LOGIC_FUNCTIONS, PATH_TMP_DIR } = require('../../test/lib/env');
const { copyAndReplaceTemplate } = require('../lib/template-processor');



Expand Down Expand Up @@ -124,8 +125,11 @@ describe('LogicFunctionCommands', () => {
const filePaths = await logicFunctionCommands.create({
params: { filepath: PATH_TMP_DIR }
});
const expectedFiles = ['logic-func-1/code.js', 'logic-func-1/configuration.json'];
// Iterate through each file path and check inclusion
expect(filePaths.length).to.equal(2);
const expectedFiles = [
path.join('logic-func-1', 'code.js'),
path.join('logic-func-1', 'configuration.json')
];
for (const expectedFile of expectedFiles) {
const includesExpected = filePaths.some(value => value.includes(expectedFile));
expect(includesExpected, `File path "${expectedFile}" does not include expected values`).to.be.true;
Expand All @@ -150,8 +154,9 @@ describe('LogicFunctionCommands', () => {
nock('https://api.particle.io/v1', )
.intercept('/logic/functions', 'GET')
.reply(200, { logic_functions: [] });
fs.createFileSync(path.join(PATH_TMP_DIR, 'logicFunc1', 'code.js'));
fs.createFileSync(path.join(PATH_TMP_DIR, 'logicFunc1', 'configuration.json'));
const templatePath = path.join(__dirname, '..', '..', 'assets', 'logicFunction');
const destinationPath = path.join(PATH_TMP_DIR, 'logicFunc1');
await copyAndReplaceTemplate({ templatePath, destinationPath, replacements: {} });
logicFunctionCommands.ui.prompt = sinon.stub();
logicFunctionCommands.ui.prompt.onCall(0).resolves({ name: 'logicFunc1' });
logicFunctionCommands.ui.prompt.onCall(1).resolves({ description: 'Logic Function 1' });
Expand Down
6 changes: 3 additions & 3 deletions src/lib/template-processor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const path = require('path');
describe('template-processor', () => {
describe('copyAndReplaceTemplate', () => {
it('copies template files to destination', async () => {
const templatePath = __dirname + '/../../assets/logicFunction';
const templatePath = path.join(__dirname, '..', '..', 'assets', 'logicFunction');
const destinationPath = path.join(PATH_TMP_DIR, 'tmp-logic-function');
const replacements = {
name: 'My Logic Function',
Expand Down Expand Up @@ -35,7 +35,7 @@ describe('template-processor', () => {
});

it('returns true if template files exist in destination', async () => {
const templatePath = __dirname + '/../../assets/logicFunction';
const templatePath = path.join(__dirname, '..', '..', 'assets', 'logicFunction');
const destinationPath = path.join(PATH_TMP_DIR, logicFunctionPath);
const replacements = {
name: 'My Logic Function',
Expand All @@ -46,7 +46,7 @@ describe('template-processor', () => {
expect(hasFiles).to.be.true;
});
it('returns false if template files do not exist in destination', async () => {
const templatePath = __dirname + '/../../assets/logicFunction';
const templatePath = path.join(__dirname, '..', '..', 'assets', 'logicFunction');
const destinationPath = path.join(PATH_TMP_DIR, logicFunctionPath);
const hasFiles = await hasTemplateFiles({ templatePath, destinationPath });
expect(hasFiles).to.be.false;
Expand Down

0 comments on commit 1e74fb4

Please sign in to comment.