Cypress + DOCX: Debugging the “Not Implemented” Error from Mammoth

Problem
I was trying to test the content of a downloaded .docx
file in Cypress using mammoth
but Cypress kept returning 'Not implemented' error which was quite confusing because the task was implemented. But after triple-checking my plugin code and re-running the test, I realized the real issue was mammoth
didn’t like the .docx
file I was trying to read.
After digging deeper, I learned this is a known limitation. Mammoth can choke when the DOCX file includes:
Word fields (
<w:fldSimple>
)Smart tags
Structured document tags (
<w:sdt>
)Comments or track changes
These elements are valid in Word, but not supported by Mammoth’s parser, hence the misleading "Not implemented" error.
Solution
Instead of relying on Mammoth, creating a simple Cypress task to extract the raw document.xml
from the .docx
file solved the problem. That way, I could assert the content of the file.
If you're running into that frustrating "Not implemented"
error while trying to test Word files in Cypress, it's probably not your code that's broken. Most likely, the .docx
itself contains something Mammoth doesn't know how to handle. Happy coding!
const unzipper = require('unzipper');
module.exports = (on, config) => {
on('task', {
extractDocumentXml({ filePath }) {
return unzipper.Open.file(filePath)
.then((directory) => {
const docXml = directory.files.find(f => f.path === 'word/document.xml');
if (!docXml) throw new Error('document.xml not found in DOCX');
return docXml.buffer();
})
.then((buffer) => buffer.toString('utf8'));
}
});
};
cy.task('extractDocumentXml', {
filePath: 'cypress/downloads/items.docx'
}).then((xml) => {
// Log or inspect the raw XML content
cy.log(xml);
expect(xml).to.include('comment');
});
Subscribe to my newsletter
Read articles from Pelin directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
