Skip to content

Commit

Permalink
Merge pull request #86 from apollographql/prettier
Browse files Browse the repository at this point in the history
chore: format all files with prettier
  • Loading branch information
lennyburdette authored Apr 29, 2021
2 parents 8aa68a8 + da7998c commit 01dd394
Show file tree
Hide file tree
Showing 46 changed files with 9,343 additions and 3,051 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,5 @@ dist

# VS Code Extension files
out
package-lock.json

.vscode-test/
.vscode-test/
13 changes: 13 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp

// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"esbenp.prettier-vscode"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": [

]
}
5,097 changes: 5,097 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@typescript-eslint/parser": "^3.0.2",
"eslint": "^7.1.0",
"mocha": "^8.2.1",
"prettier": "^2.2.1",
"typescript": "^4.0.2",
"vsce": "^1.83.0",
"vscode-test": "^1.4.1"
Expand All @@ -66,6 +67,11 @@
"node-fetch": "^2.6.1",
"vscode-languageclient": "^6.1.3"
},
"prettier": {
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all"
},
"contributes": {
"configuration": {
"title": "Apollo-Workbench",
Expand Down
38 changes: 24 additions & 14 deletions src/__tests__/githubCheckTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ const fetch = require('node-fetch');
import { testRunner } from './testRunner';

async function setStatus(state, description) {
return fetch(`https://api.github.com/repos/apollographql/apollo-workbench-vscode/statuses/${process.env.GITHUB_SHA}`, {
method: 'POST',
body: JSON.stringify({
state,
description,
context: "VSCode Extension Tests",
}),
headers: {
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
'Content-Type': 'application/json',
return fetch(
`https://api.github.com/repos/apollographql/apollo-workbench-vscode/statuses/${process.env.GITHUB_SHA}`,
{
method: 'POST',
body: JSON.stringify({
state,
description,
context: 'VSCode Extension Tests',
}),
headers: {
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
'Content-Type': 'application/json',
},
},
});
);
}

async function githubActionTests() {
Expand All @@ -30,10 +33,17 @@ async function githubActionTests() {
await setStatus('success', 'Tests for workbench folder open passed');
process.exit(result);
} catch (err) {
console.log(err?.message ? `Failed to run tests: ${err.message}` : `Failed to run tests: ${err}`);
await setStatus('error', err?.message ? err.message : `Failed to run tests: ${err}`);
console.log(
err?.message
? `Failed to run tests: ${err.message}`
: `Failed to run tests: ${err}`,
);
await setStatus(
'error',
err?.message ? err.message : `Failed to run tests: ${err}`,
);
process.exit(1);
}
}

githubActionTests();
githubActionTests();
54 changes: 31 additions & 23 deletions src/__tests__/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,40 @@ import * as path from 'path';

import { runTests } from 'vscode-test';

async function mainTestRunner(loadFolder: boolean = false) {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
async function mainTestRunner(loadFolder = false) {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../../');

// The path to the extension test script
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, './suite/index');
const testWorkbenchFolder = path.resolve(__dirname, './test-workbench');
// The path to the extension test script
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, './suite/index');
const testWorkbenchFolder = path.resolve(__dirname, './test-workbench');

// let shouldLoadWorkbenchFolder = process.argv[2];
// console.log('******shouldLoadWorkbenchFolder:' + shouldLoadWorkbenchFolder);
// let shouldLoadWorkbenchFolder = process.argv[2];
// console.log('******shouldLoadWorkbenchFolder:' + shouldLoadWorkbenchFolder);

// console.log('******extensionDevelopmentPath:' + extensionDevelopmentPath);
// console.log('******extensionTestsPath:' + extensionTestsPath);
// console.log('******testWorkbenchFolder:' + testWorkbenchFolder);
// console.log('******extensionDevelopmentPath:' + extensionDevelopmentPath);
// console.log('******extensionTestsPath:' + extensionTestsPath);
// console.log('******testWorkbenchFolder:' + testWorkbenchFolder);

if (loadFolder)
await runTests({ extensionDevelopmentPath, extensionTestsPath, launchArgs: [testWorkbenchFolder, '--disable-extensions'] });
else
await runTests({ extensionDevelopmentPath, extensionTestsPath, launchArgs: ['--disable-extensions'] });
} catch (err) {
console.error('Failed to run tests');
process.exit(1);
}
if (loadFolder)
await runTests({
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: [testWorkbenchFolder, '--disable-extensions'],
});
else
await runTests({
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: ['--disable-extensions'],
});
} catch (err) {
console.error('Failed to run tests');
process.exit(1);
}
}

mainTestRunner();
mainTestRunner();
46 changes: 28 additions & 18 deletions src/__tests__/suite/defaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,36 @@ import { StateManager } from '../../workbench/stateManager';
import { NotLoggedInTreeItem } from '../../workbench/tree-data-providers/apolloStudioGraphsTreeDataProvider';

suite('Default Workbench Tests', () => {
before(activateExtension);
before(activateExtension);

it('Defaults:StudioGraphs - Should display login item', async function () {
//Setup
StateManager.instance.globalState_userApiKey = "";
it('Defaults:StudioGraphs - Should display login item', async function () {
//Setup
StateManager.instance.globalState_userApiKey = '';

//Get TreeView children
const studioGraphTreeItems = await StateManager.instance.apolloStudioGraphsProvider.getChildren();
//Get TreeView children
const studioGraphTreeItems = await StateManager.instance.apolloStudioGraphsProvider.getChildren();

//Assert
studioGraphTreeItems.forEach(studioGraphTreeItem => assert.notStrictEqual(studioGraphTreeItem as NotLoggedInTreeItem, undefined));
});
it('Defaults:StudioOperations - Should display login item', async function () {
//Setup
StateManager.instance.globalState_userApiKey = "";
//Assert
studioGraphTreeItems.forEach((studioGraphTreeItem) =>
assert.notStrictEqual(
studioGraphTreeItem as NotLoggedInTreeItem,
undefined,
),
);
});
it('Defaults:StudioOperations - Should display login item', async function () {
//Setup
StateManager.instance.globalState_userApiKey = '';

//Get TreeView children
const studioGraphTreeItems = await StateManager.instance.apolloStudioGraphsProvider.getChildren();
//Get TreeView children
const studioGraphTreeItems = await StateManager.instance.apolloStudioGraphsProvider.getChildren();

//Assert
studioGraphTreeItems.forEach(studioGraphTreeItem => assert.notStrictEqual(studioGraphTreeItem as NotLoggedInTreeItem, undefined));
});
});
//Assert
studioGraphTreeItems.forEach((studioGraphTreeItem) =>
assert.notStrictEqual(
studioGraphTreeItem as NotLoggedInTreeItem,
undefined,
),
);
});
});
22 changes: 14 additions & 8 deletions src/__tests__/suite/extension.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import * as assert from 'assert';
import { suite, it } from 'mocha'
import { activateExtension, cleanupWorkbenchFiles, createAndLoadEmptyWorkbenchFile, simpleSchema } from './helpers';
import { suite, it } from 'mocha';
import {
activateExtension,
cleanupWorkbenchFiles,
createAndLoadEmptyWorkbenchFile,
simpleSchema,
} from './helpers';
import { FileProvider } from '../../workbench/file-system/fileProvider';
import { StateManager } from '../../workbench/stateManager';
import { WorkbenchUri, WorkbenchUriType } from '../../workbench/file-system/WorkbenchUri';
import {
WorkbenchUri,
WorkbenchUriType,
} from '../../workbench/file-system/WorkbenchUri';

const key = 'Loaded-Folder';

suite(key, () => {
before(activateExtension);
afterEach(cleanupWorkbenchFiles);


})
before(activateExtension);
afterEach(cleanupWorkbenchFiles);
});
53 changes: 26 additions & 27 deletions src/__tests__/suite/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,43 @@ import { readdirSync, unlinkSync } from 'fs';
import { FileProvider } from '../../workbench/file-system/fileProvider';

export const activateExtension = async () => {
return new Promise<void>(async (resolve) => {
let extension = vscode.extensions.getExtension('ApolloGraphQL.apollo-workbench-vscode');
if (extension) {
await extension.activate();
}
resolve();
});
}
return new Promise<void>(async (resolve) => {
let extension = vscode.extensions.getExtension(
'ApolloGraphQL.apollo-workbench-vscode',
);
if (extension) {
await extension.activate();
}
resolve();
});
};

export function cleanupWorkbenchFiles() {
try {
const directory = path.resolve(__dirname, '..', './test-workbench');
const dirents = readdirSync(directory, { withFileTypes: true });
for (const dirent of dirents) {
if (dirent.isFile() && dirent.name.includes('.apollo-workbench'))
unlinkSync(path.resolve(directory, dirent.name));
}
} catch (err) {
console.log(`Cleanup Error: ${err}`);
try {
const directory = path.resolve(__dirname, '..', './test-workbench');
const dirents = readdirSync(directory, { withFileTypes: true });
for (const dirent of dirents) {
if (dirent.isFile() && dirent.name.includes('.apollo-workbench'))
unlinkSync(path.resolve(directory, dirent.name));
}
FileProvider.instance.clearWorkbenchFiles();
} catch (err) {
console.log(`Cleanup Error: ${err}`);
}
FileProvider.instance.clearWorkbenchFiles();
}


export async function createAndLoadEmptyWorkbenchFile() {
// const workbenchFileName = 'empty-workbench';
// const workbenchFilePath = FileProvider.instance.createNewWorkbenchFile(workbenchFileName);
// if (!workbenchFilePath) throw new Error('Workbench file was not created');

// await FileProvider.instance.loadWorkbenchFile(workbenchFileName, workbenchFilePath);
// const workbenchFileName = 'empty-workbench';
// const workbenchFilePath = FileProvider.instance.createNewWorkbenchFile(workbenchFileName);
// if (!workbenchFilePath) throw new Error('Workbench file was not created');
// await FileProvider.instance.loadWorkbenchFile(workbenchFileName, workbenchFilePath);
}

export const simpleSchema =
`
export const simpleSchema = `
type A @key(fields:"id"){
id: ID!
}
extend type Query {
a: A
}
`;
`;
67 changes: 33 additions & 34 deletions src/__tests__/suite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,42 @@ import glob from 'glob';
import { StateManager } from '../../workbench/stateManager';

export function run(): Promise<void> {
// Create the mocha test
const mocha = new Mocha({
ui: 'tdd'
});
// Create the mocha test
const mocha = new Mocha({
ui: 'tdd',
});

const testsRoot = path.resolve(__dirname, '..');
let isWorkbenchFolderLoaded = StateManager.workspaceRoot ? true : false;
const testsRoot = path.resolve(__dirname, '..');
let isWorkbenchFolderLoaded = StateManager.workspaceRoot ? true : false;

return new Promise((c, e) => {
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
if (err) {
return e(err);
}
return new Promise((c, e) => {
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
if (err) {
return e(err);
}

// Add files to the test suite
files.forEach(f => {
if (f.includes('defaults'))
mocha.addFile(path.resolve(testsRoot, f))
else if (isWorkbenchFolderLoaded && !f.includes('noFolder'))
mocha.addFile(path.resolve(testsRoot, f))
else if (!isWorkbenchFolderLoaded && f.includes('noFolder'))
mocha.addFile(path.resolve(testsRoot, f))
});
// Add files to the test suite
files.forEach((f) => {
if (f.includes('defaults')) mocha.addFile(path.resolve(testsRoot, f));
else if (isWorkbenchFolderLoaded && !f.includes('noFolder'))
mocha.addFile(path.resolve(testsRoot, f));
else if (!isWorkbenchFolderLoaded && f.includes('noFolder'))
mocha.addFile(path.resolve(testsRoot, f));
});

try {
// Run the mocha test
mocha.run(failures => {
if (failures > 0) {
e(new Error(`${failures} tests failed.`));
} else {
c();
}
});
} catch (err) {
console.error(`Mocha Run Error: ${err}`);
e(err);
}
try {
// Run the mocha test
mocha.run((failures) => {
if (failures > 0) {
e(new Error(`${failures} tests failed.`));
} else {
c();
}
});
} catch (err) {
console.error(`Mocha Run Error: ${err}`);
e(err);
}
});
}
});
}
Loading

0 comments on commit 01dd394

Please sign in to comment.