Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions services/rekoni/src/__tests__/docx.smoke.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright © 2026 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.

import { readFile } from 'fs/promises'
import { join } from 'path'
import { extract } from '../extractors'

const DOCX_TYPE = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'

describe('docx extractor smoke', () => {
it('extracts plain text from a minimal docx', async () => {
const fName = join(__dirname, 'fixtures', 'minimal-smoke.docx')
const data = await readFile(fName)

const { matched, content, error } = await extract('minimal-smoke.docx', DOCX_TYPE, data)

expect(error).toBeUndefined()
expect(matched).toBe(true)
expect(content).toContain('Hello DOCX smoke test')
})
})
Binary file not shown.
20 changes: 13 additions & 7 deletions services/rekoni/src/extractors/docx.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
// Copyright © 2026 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
import { convertToHtml, images } from 'mammoth'
import { contentType } from 'mime-types'
import { DocumentExtractor } from './types'
Expand All @@ -19,13 +31,7 @@ export const docxExtractor: DocumentExtractor = {
const htmlData = await convertToHtml(
{ buffer: data },
{
convertImage: images.imgElement((image) => {
return image.read('base64').then(function (imageBuffer) {
return {
src: ''
}
})
})
convertImage: images.imgElement(async () => ({ src: '' }))
}
)

Expand Down
Loading