Skip to content

Commit

Permalink
Change working directory for test.
Browse files Browse the repository at this point in the history
  • Loading branch information
sfdctaka committed Nov 19, 2024
1 parent 281fc8d commit a6b5397
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 31 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@
"scripts": {
"clean": "rimraf ./out",
"compile": "rimraf ./out/tsconfig.tsbuildinfo && tsc -b ./ && npm run copy-yaml",
"copy-yaml": "mkdir -p './out/src/resources' && cp './resources/component-experiences.yaml' './out/src/resources/component-experiences.yaml'",
"copy-yaml-win": "mkdir out\\src\\resources && copy resources\\component-experiences.yaml out\\src\\resources",
"copy-yaml-unix": "mkdir -p ./out/src/resources && cp ./resources/component-experiences.yaml ./out/src/resources",
"copy-yaml": "npm run copy-yaml-win || npm run copy-yaml-unix",
"watch": "tsc -watch -b ./",
"pretest": "npm run compile && npm run lint",
"lint": "eslint src --ext ts",
Expand Down
3 changes: 2 additions & 1 deletion src/lsp/server/diagnostics/html/mobileOfflineFriendly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ function getKeysWithoutSpecificValue(
}

function getBaseComponentsAttributes(): Record<string, string[]> {
const yamlPath = path.join(
//const yamlPath = path.join(
const yamlPath = path.resolve(
__dirname,
'..',
'..',
Expand Down
2 changes: 1 addition & 1 deletion src/lsp/server/utils/serverWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class ServerWorkspace {
workspaceFolders: WorkspaceFolder[] | null | undefined
) {
if (workspaceFolders === undefined) {
throw new Error('LSP client requires workspace folder.');
throw new Error('A valid workspace folder needs to be set for Salesforce Mobile Language Server to function.');
}
this.workspaceFolders = workspaceFolders;
}
Expand Down
5 changes: 2 additions & 3 deletions test/TestHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as process from 'process';
import * as sinon from 'sinon';
import { WorkspaceUtils } from '../src/utils/workspaceUtils';

import { readFileSync } from 'fs';
import * as Account from './suite/lsp/server/testFixture/objectInfos/Account.json';
import {
ConfigAggregator,
StateAggregator,
Expand Down Expand Up @@ -143,8 +143,7 @@ export function stubCreateConnection(
sandbox: sinon.SinonSandbox,
requestable: boolean
) {
const account = JSON.parse(readFileSync('test/suite/lsp/server/testFixture/objectInfos/Account.json', 'utf-8'));
const mockRequest = sandbox.stub().resolves(account);
const mockRequest = sandbox.stub().resolves(Account);
const mockConnection = requestable
? {
getUsername: sandbox.stub().returns('tester'),
Expand Down
2 changes: 1 addition & 1 deletion test/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async function main() {
console.error(installNonZeroError);
throw new Error(installNonZeroError);
}

// All clear! Should be able to run the tests.
await runTests({
extensionDevelopmentPath,
Expand Down
17 changes: 3 additions & 14 deletions test/suite/lsp/server/diagnostics/gql/over-sized-record.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@

import { TextDocument } from 'vscode-languageserver-textdocument';
import { suite, test, beforeEach, afterEach } from 'mocha';
import { readFileSync } from 'fs';
import * as Book__c from '../../testFixture/objectInfos/Book__c.json';
import * as assert from 'assert';
import * as sinon from 'sinon';
import * as path from 'path';
import { parse } from 'graphql';
import {
OversizedRecord,
Expand All @@ -24,24 +23,14 @@ import { ObjectInfoRepresentation } from '../../../../../../src/lsp/server/types
suite(
'GraphQL Diagnostics Test Suite - Server - Oversized GraphQL Field',
() => {
let sandbox: sinon.SinonSandbox;
let oversizedRecordProducer = new OversizedRecord();

const cwd = process.cwd();
console.log('----------------------');
console.error('----------------------');
console.log(cwd);
console.error(cwd);
console.log('----------------------');
console.error('----------------------');
const testFixturePath = path.resolve(cwd, 'test/suite/lsp/server/testFixture/objectInfos/Book__c.json');
const book = JSON.parse(readFileSync(testFixturePath, 'utf-8'));

let sandbox: sinon.SinonSandbox;
beforeEach(function () {
sandbox = sinon.createSandbox();
sandbox
.stub(OrgUtils, 'getObjectInfo')
.resolves(book as unknown as ObjectInfoRepresentation);
.resolves(Book__c as unknown as ObjectInfoRepresentation);
});

afterEach(function () {
Expand Down
13 changes: 6 additions & 7 deletions test/suite/lsp/server/utils/gqlUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

import { TextDocument } from 'vscode-languageserver-textdocument';
import { suite, test, beforeEach, afterEach } from 'mocha';
import { readFileSync } from 'fs';
import * as Account from '../testFixture/objectInfos/Account.json';
import * as User from '../testFixture/objectInfos/User.json';
import * as Contact from '../testFixture/objectInfos/Contact.json';

import * as assert from 'assert';
import * as sinon from 'sinon';
Expand All @@ -28,19 +30,16 @@ suite('GraphQL Utils Test Suite - Server', () => {
});

test('Entity tree with relationship is generated for ObjectInfo retrieval', async () => {
const account = JSON.parse(readFileSync('test/suite/lsp/server/testFixture/objectInfos/Account.json', 'utf-8'));
const user = JSON.parse(readFileSync('test/suite/lsp/server/testFixture/objectInfos/User.json', 'utf-8'));
const contact = JSON.parse(readFileSync('test/suite/lsp/server/testFixture/objectInfos/Contact.json', 'utf-8'));
const getObjectInfoStub = sandbox.stub(OrgUtils, 'getObjectInfo');
getObjectInfoStub
.onCall(0)
.resolves(account as unknown as ObjectInfoRepresentation);
.resolves(Account as unknown as ObjectInfoRepresentation);
getObjectInfoStub
.onCall(1)
.resolves(user as unknown as ObjectInfoRepresentation);
.resolves(User as unknown as ObjectInfoRepresentation);
getObjectInfoStub
.onCall(2)
.resolves(contact as unknown as ObjectInfoRepresentation);
.resolves(Contact as unknown as ObjectInfoRepresentation);

const textDocument = TextDocument.create(
'',
Expand Down
5 changes: 2 additions & 3 deletions test/suite/lsp/server/validators/graphqlValidator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@ import * as assert from 'assert';
import { suite, test, beforeEach, afterEach } from 'mocha';
import * as sinon from 'sinon';
import { OrgUtils } from '../../../../../src/lsp/server/utils/orgUtils';
import { readFileSync } from 'fs';
import * as Book__c from '../testFixture/objectInfos/Book__c.json';
import { ObjectInfoRepresentation } from '../../../../../src/lsp/server/types';

suite('Diagnostics Test Suite - Server - GraphQL Validator', () => {
const book = JSON.parse(readFileSync('test/suite/lsp/server/testFixture/objectInfos/Book__c.json', 'utf-8'));
let sandbox: sinon.SinonSandbox;
beforeEach(function () {
sandbox = sinon.createSandbox();
sandbox
.stub(OrgUtils, 'getObjectInfo')
.resolves(book as unknown as ObjectInfoRepresentation);
.resolves(Book__c as unknown as ObjectInfoRepresentation);
});

afterEach(function () {
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"lib": ["es2020"],
"sourceMap": true,
"rootDir": ".",
"resolveJsonModule": true,
"strict": true /* enable all strict type-checking options */
/* Additional Checks */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
Expand Down

0 comments on commit a6b5397

Please sign in to comment.