diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index bb68bdf..bb6d53b 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -4,6 +4,8 @@ name: Node.js CI on: + push: + branches: [ main ] pull_request: branches: [ main ] @@ -25,4 +27,5 @@ jobs: node-version: ${{ matrix.node-version }} cache: 'npm' - run: npm ci + - run: npm run build --if-present - run: npm test diff --git a/test/compose.js b/test/compose.js index 649b56d..af160d4 100644 --- a/test/compose.js +++ b/test/compose.js @@ -41,16 +41,37 @@ describe('compose', function () { (async () => { var report = await compose.up(); expect(report.services).to.be.ok; - await new Promise(r => setTimeout(r, 2000)); - let listContainers = await docker.listContainers({ 'all': true }); - for (var containerInfo of listContainers) { - if (containerInfo.Names[0].includes("dockerodec_wordpress")) { - let container = docker.getContainer(containerInfo.Id); - if (containerInfo.State == 'running') - await container.stop(); - await container.remove(); - } - } + done(); + })(); + }); + afterEach('clean up', function (done) { + this.timeout(60000); + (async () => { + await compose.down({ volumes: true }); + done(); + })(); + }); + }); + + describe('#down', function () { + beforeEach('bring up', function (done) { + this.timeout(20000); + (async () => { + await compose.up(); + done(); + })(); + }); + it("should do compose down", function (done) { + this.timeout(60000); + (async () => { + await compose.down({volumes: true}); + let listContainers = await docker.listContainers({ 'all': true, 'filters': {"label":[`com.docker.compose.project=${compose.projectName}`]}}); + expect(listContainers).to.be.empty + let listVolumes = await docker.listVolumes({ 'filters': {"label":[`com.docker.compose.project=${compose.projectName}`]}}) + expect(listVolumes.Volumes).to.be.empty + expect(listVolumes.Warnings).to.be.null + let listNetworks = await docker.listNetworks({ 'filters': {"label":[`com.docker.compose.project=${compose.projectName}`]}}) + expect(listNetworks).to.be.empty done(); })(); }); @@ -62,16 +83,37 @@ describe('compose', function () { (async () => { var report = await compose_complex.up(); expect(report.services).to.be.ok; - await new Promise(r => setTimeout(r, 5000)); - let listContainers = await docker.listContainers({ 'all': true }); - for (var containerInfo of listContainers) { - if (containerInfo.Names[0].includes("dockerodec_complex")) { - let container = docker.getContainer(containerInfo.Id); - if (containerInfo.State == 'running') - await container.stop(); - await container.remove(); - } - } + done(); + })(); + }); + afterEach('clean up', function (done) { + this.timeout(60000); + (async () => { + await compose_complex.down({ volumes: true }); + done(); + })(); + }); + }); + + describe('#down_complex', function () { + beforeEach('bring up', function (done) { + this.timeout(300000); + (async () => { + await compose_complex.up(); + done(); + })(); + }); + it("should do compose down complex example with extends and build", function (done) { + this.timeout(60000); + (async () => { + await compose_complex.down({volumes: true}); + let listContainers = await docker.listContainers({ 'all': true, 'filters': {"label":[`com.docker.compose.project=${compose.projectName}`]}}); + expect(listContainers).to.be.empty + let listVolumes = await docker.listVolumes({ 'filters': {"label":[`com.docker.compose.project=${compose.projectName}`]}}) + expect(listVolumes.Volumes).to.be.empty + expect(listVolumes.Warnings).to.be.null + let listNetworks = await docker.listNetworks({ 'filters': {"label":[`com.docker.compose.project=${compose.projectName}`]}}) + expect(listNetworks).to.be.empty done(); })(); }); @@ -83,16 +125,6 @@ describe('compose', function () { (async () => { var report = await compose_build.up(); expect(report.services).to.be.ok; - await new Promise(r => setTimeout(r, 5000)); - let listContainers = await docker.listContainers({ 'all': true }); - for (var containerInfo of listContainers) { - if (containerInfo.Names[0].includes("dockerodec_build")) { - let container = docker.getContainer(containerInfo.Id); - if (containerInfo.State == 'running') - await container.stop(); - await container.remove(); - } - } done(); })(); }); @@ -101,16 +133,37 @@ describe('compose', function () { (async () => { var report = await compose_build.up({ 'verbose': true }); expect(report.services).to.be.ok; - await new Promise(r => setTimeout(r, 5000)); - let listContainers = await docker.listContainers({ 'all': true }); - for (var containerInfo of listContainers) { - if (containerInfo.Names[0].includes("dockerodec_build")) { - let container = docker.getContainer(containerInfo.Id); - if (containerInfo.State == 'running') - await container.stop(); - await container.remove(); - } - } + done(); + })(); + }); + afterEach('clean up', function (done) { + this.timeout(60000); + (async () => { + await compose_build.down({ volumes: true }); + done(); + })(); + }); + }); + + describe('#down_build', function () { + beforeEach('bring up', function (done) { + this.timeout(300000); + (async () => { + await compose_build.up(); + done(); + })(); + }); + it("should do compose down example with build", function (done) { + this.timeout(60000); + (async () => { + await compose_build.down({volumes: true}); + let listContainers = await docker.listContainers({ 'all': true, 'filters': {"label":[`com.docker.compose.project=${compose.projectName}`]}}); + expect(listContainers).to.be.empty + let listVolumes = await docker.listVolumes({ 'filters': {"label":[`com.docker.compose.project=${compose.projectName}`]}}) + expect(listVolumes.Volumes).to.be.empty + expect(listVolumes.Warnings).to.be.null + let listNetworks = await docker.listNetworks({ 'filters': {"label":[`com.docker.compose.project=${compose.projectName}`]}}) + expect(listNetworks).to.be.empty done(); })(); });