Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 1500701

Browse files
create leak free tests for initialize
1 parent eefdd00 commit 1500701

File tree

1 file changed

+80
-16
lines changed

1 file changed

+80
-16
lines changed

test/github-package.test.js

Lines changed: 80 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,10 @@ describe('GithubPackage', function() {
830830

831831
fs.writeFileSync(path.join(workdirPath1, 'c.txt'), 'ch-ch-ch-changes', 'utf8');
832832
fs.writeFileSync(path.join(workdirPath2, 'c.txt'), 'ch-ch-ch-changes', 'utf8');
833+
});
833834

835+
// Setup up GitHub Package and file watchers
836+
beforeEach(async function() {
834837
project.setPaths([workdirPath1, workdirPath2]);
835838
await githubPackage.activate();
836839

@@ -845,7 +848,10 @@ describe('GithubPackage', function() {
845848
}
846849

847850
await Promise.all(watcherPromises);
851+
});
848852

853+
// Stub the repositories functions
854+
beforeEach(function() {
849855
[atomGitRepository1, atomGitRepository2] = githubPackage.project.getRepositories();
850856
sinon.stub(atomGitRepository1, 'refreshStatus');
851857
sinon.stub(atomGitRepository2, 'refreshStatus');
@@ -856,11 +862,17 @@ describe('GithubPackage', function() {
856862
sinon.stub(repository2, 'observeFilesystemChange');
857863
});
858864

865+
// Destroy Atom Environment and the GitHub Package
866+
afterEach(async function() {
867+
await githubPackage.deactivate();
868+
869+
atomEnv.destroy();
870+
});
871+
859872
it('refreshes the appropriate Repository and Atom GitRepository when a file is changed in workspace 1', async function() {
860873
if (process.platform === 'linux') {
861874
this.skip();
862875
}
863-
this.retries(5); // FLAKE
864876

865877
fs.writeFileSync(path.join(workdirPath1, 'a.txt'), 'some changes', 'utf8');
866878

@@ -872,7 +884,6 @@ describe('GithubPackage', function() {
872884
if (process.platform === 'linux') {
873885
this.skip();
874886
}
875-
this.retries(5); // FLAKE
876887

877888
fs.writeFileSync(path.join(workdirPath2, 'b.txt'), 'other changes', 'utf8');
878889

@@ -895,24 +906,77 @@ describe('GithubPackage', function() {
895906
});
896907
});
897908

898-
/*describe('initialize', function() {
899-
it('creates and sets a repository for the given project path', async function() {
900-
const nonRepositoryPath = await getTempDir();
901-
project.setPaths([nonRepositoryPath]);
909+
describe('initialize()', function() {
910+
let atomEnv, githubPackage;
911+
let workspace, project, commands, notificationManager;
912+
let tooltips, deserializers, config, keymaps, styles;
913+
let grammars, confirm, configDirPath, getLoadSettings;
914+
let renderFn, contextPool, currentWindow;
915+
let useLegacyPanels;
902916

903-
await contextUpdateAfter(githubPackage, () => githubPackage.activate());
904-
await githubPackage.getActiveRepository().getLoadPromise();
917+
beforeEach(async function() {
918+
atomEnv = global.buildAtomEnvironment();
919+
await disableFilesystemWatchers(atomEnv);
920+
921+
workspace = atomEnv.workspace;
922+
project = atomEnv.project;
923+
commands = atomEnv.commands;
924+
deserializers = atomEnv.deserializers;
925+
notificationManager = atomEnv.notifications;
926+
tooltips = atomEnv.tooltips;
927+
config = atomEnv.config;
928+
keymaps = atomEnv.keymaps;
929+
confirm = atomEnv.confirm.bind(atomEnv);
930+
styles = atomEnv.styles;
931+
grammars = atomEnv.grammars;
932+
getLoadSettings = atomEnv.getLoadSettings.bind(atomEnv);
933+
currentWindow = atomEnv.getCurrentWindow();
934+
configDirPath = path.join(__dirname, 'fixtures', 'atomenv-config');
935+
renderFn = sinon.stub().callsFake((component, element, callback) => {
936+
if (callback) {
937+
process.nextTick(callback);
938+
}
939+
});
940+
941+
useLegacyPanels = !workspace.getLeftDock;
942+
943+
githubPackage = new GithubPackage({
944+
workspace, project, commands, notificationManager, tooltips,
945+
styles, grammars, keymaps, config, deserializers, confirm,
946+
getLoadSettings, currentWindow, configDirPath, renderFn,
947+
});
905948

906-
assert.isTrue(githubPackage.getActiveRepository().isEmpty());
907-
assert.isFalse(githubPackage.getActiveRepository().isAbsent());
949+
contextPool = githubPackage.getContextPool();
950+
});
908951

909-
await githubPackage.initialize(nonRepositoryPath);
952+
afterEach(async function() {
953+
await githubPackage.deactivate();
910954

911-
assert.isTrue(githubPackage.getActiveRepository().isPresent());
912-
assert.strictEqual(
913-
githubPackage.getActiveRepository(),
914-
await contextPool.getContext(nonRepositoryPath).getRepository(),
915-
);
955+
atomEnv.destroy();
956+
});
957+
958+
context('with a non-repository project', function() {
959+
let nonRepositoryPath;
960+
beforeEach(async function() {
961+
nonRepositoryPath = await getTempDir();
962+
project.setPaths([nonRepositoryPath]);
963+
964+
await contextUpdateAfter(githubPackage, () => githubPackage.activate());
965+
await githubPackage.getActiveRepository().getLoadPromise();
966+
967+
await githubPackage.initialize(nonRepositoryPath);
968+
});
969+
970+
it('creates a repository for the project', function() {
971+
assert.isTrue(githubPackage.getActiveRepository().isPresent());
972+
});
973+
974+
it('uses the newly created repository for the project', async function() {
975+
assert.strictEqual(
976+
githubPackage.getActiveRepository(),
977+
await contextPool.getContext(nonRepositoryPath).getRepository(),
978+
);
979+
});
916980
});
917981
});
918982

0 commit comments

Comments
 (0)