Skip to content

Commit

Permalink
chore: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Feb 13, 2024
1 parent 554968f commit 77e27b2
Show file tree
Hide file tree
Showing 8 changed files with 1,332 additions and 1,298 deletions.
357 changes: 180 additions & 177 deletions src/can-deploy/can-deploy.spec.ts

Large diffs are not rendered by default.

218 changes: 111 additions & 107 deletions src/message.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,134 +9,138 @@ import messageFactory from './message';
const { expect } = chai;
chai.use(chaiAsPromised);

(process.env['SKIP_STANDALONE'] === "true" ? describe.skip : describe )('Message Spec', () => {
const validJSON = `{ "description": "a test mesage", "content": { "name": "Mary" } }`;
(process.env['SKIP_STANDALONE'] === 'true' ? describe.skip : describe)(
'Message Spec',
() => {
const validJSON = `{ "description": "a test mesage", "content": { "name": "Mary" } }`;

let absolutePath: string;
let relativePath: string;
beforeEach(() => {
relativePath = `.tmp/${Math.floor(Math.random() * 1000)}`;
absolutePath = path.resolve(__dirname, '..', relativePath);
mkdirp.sync(absolutePath);
});
let absolutePath: string;
let relativePath: string;
beforeEach(() => {

Check warning on line 19 in src/message.spec.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, amd64, false, false, 16)

Unexpected use of Mocha `beforeEach` hook outside of a test suite

Check warning on line 19 in src/message.spec.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, amd64, false, false, 18)

Unexpected use of Mocha `beforeEach` hook outside of a test suite

Check warning on line 19 in src/message.spec.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, amd64, false, false, 20)

Unexpected use of Mocha `beforeEach` hook outside of a test suite
relativePath = `.tmp/${Math.floor(Math.random() * 1000)}`;
absolutePath = path.resolve(__dirname, '..', relativePath);
mkdirp.sync(absolutePath);
});

afterEach(() => {
if (fs.existsSync(absolutePath)) {
rimraf.sync(absolutePath);
}
});
afterEach(() => {

Check warning on line 25 in src/message.spec.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, amd64, false, false, 16)

Unexpected use of Mocha `afterEach` hook outside of a test suite

Check warning on line 25 in src/message.spec.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, amd64, false, false, 18)

Unexpected use of Mocha `afterEach` hook outside of a test suite

Check warning on line 25 in src/message.spec.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, amd64, false, false, 20)

Unexpected use of Mocha `afterEach` hook outside of a test suite
if (fs.existsSync(absolutePath)) {
rimraf.sync(absolutePath);
}
});

context('when invalid options are set', () => {
it('should throw an Error when not given any message content', () => {
expect(() =>
messageFactory({
consumer: 'a-consumer',
dir: absolutePath,
})
).to.throw(Error);
context('when invalid options are set', () => {
it('should throw an Error when not given any message content', () => {
expect(() =>
messageFactory({
consumer: 'a-consumer',
dir: absolutePath,
})
).to.throw(Error);
});

it('should throw an Error when not given a consumer', () => {
expect(() =>
messageFactory({
provider: 'a-provider',
dir: absolutePath,
content: validJSON,
})
).to.throw(Error);
});

it('should throw an Error when not given a provider', () => {
expect(() =>
messageFactory({
consumer: 'a-provider',
dir: absolutePath,
content: validJSON,
})
).to.throw(Error);
});

it('should throw an Error when given an invalid JSON document', () => {
expect(() =>
messageFactory({
consumer: 'some-consumer',
provider: 'a-provider',
dir: absolutePath,
content: `{ "unparseable" }`,
})
).to.throw(Error);
});

it('should throw an Error when not given a pact dir', () => {
expect(() =>
messageFactory({
consumer: 'a-consumer',
content: validJSON,
})
).to.throw(Error);
});
});

it('should throw an Error when not given a consumer', () => {
expect(() =>
messageFactory({
context('when valid options are set', () => {
it('should return a message object when given the correct arguments', () => {
const message = messageFactory({
consumer: 'some-consumer',
provider: 'a-provider',
dir: absolutePath,
content: validJSON,
})
).to.throw(Error);
});
});
expect(message).to.be.a('object');
expect(message).to.respondTo('createMessage');
});

it('should throw an Error when not given a provider', () => {
expect(() =>
messageFactory({
consumer: 'a-provider',
it('should return a promise when calling createMessage', () => {
const promise = messageFactory({
consumer: 'some-consumer',
provider: 'a-provider',
dir: absolutePath,
content: validJSON,
})
).to.throw(Error);
});
}).createMessage();
expect(promise).to.ok;
return expect(promise).to.eventually.be.fulfilled;
});

it('should throw an Error when given an invalid JSON document', () => {
expect(() =>
messageFactory({
it("should create a new directory if the directory specified doesn't exist yet", () => {
const dir = path.resolve(absolutePath, 'create');
return messageFactory({
consumer: 'some-consumer',
provider: 'a-provider',
dir: absolutePath,
content: `{ "unparseable" }`,
})
).to.throw(Error);
});

it('should throw an Error when not given a pact dir', () => {
expect(() =>
messageFactory({
consumer: 'a-consumer',
dir,
content: validJSON,
})
).to.throw(Error);
});
});

context('when valid options are set', () => {
it('should return a message object when given the correct arguments', () => {
const message = messageFactory({
consumer: 'some-consumer',
provider: 'a-provider',
dir: absolutePath,
content: validJSON,
.createMessage()
.then(() => expect(fs.existsSync(dir)).to.be.true);
});
expect(message).to.be.a('object');
expect(message).to.respondTo('createMessage');
});

it('should return a promise when calling createMessage', () => {
const promise = messageFactory({
consumer: 'some-consumer',
provider: 'a-provider',
dir: absolutePath,
content: validJSON,
}).createMessage();
expect(promise).to.ok;
return expect(promise).to.eventually.be.fulfilled;
});

it("should create a new directory if the directory specified doesn't exist yet", () => {
const dir = path.resolve(absolutePath, 'create');
return messageFactory({
consumer: 'some-consumer',
provider: 'a-provider',
dir,
content: validJSON,
})
.createMessage()
.then(() => expect(fs.existsSync(dir)).to.be.true);
});
it('should return an absolute path when a relative one is given', () => {
const dir = path.join(relativePath, 'create');
expect(
messageFactory({
consumer: 'some-consumer',
provider: 'a-provider',
dir,
content: validJSON,
}).options.dir
).to.equal(path.resolve(__dirname, '..', dir));
});

it('should return an absolute path when a relative one is given', () => {
const dir = path.join(relativePath, 'create');
expect(
messageFactory({
it('should create a new directory with a relative path', () => {
const dir = path.join(relativePath, 'create');
return messageFactory({
consumer: 'some-consumer',
provider: 'a-provider',
dir,
content: validJSON,
}).options.dir
).to.equal(path.resolve(__dirname, '..', dir));
});

it('should create a new directory with a relative path', () => {
const dir = path.join(relativePath, 'create');
return messageFactory({
consumer: 'some-consumer',
provider: 'a-provider',
dir,
content: validJSON,
})
.createMessage()
.then(
() =>
expect(fs.existsSync(path.resolve(__dirname, '..', dir))).to.be.true
);
})
.createMessage()
.then(
() =>
expect(fs.existsSync(path.resolve(__dirname, '..', dir))).to.be
.true
);
});
});
});
});
}
);
Loading

0 comments on commit 77e27b2

Please sign in to comment.